Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB, the way to store formatted text with images for blogging application

I need to implement a blogging application using .NET and MongoDB. What is the right way to store blog posts / articles that people write? Suppose user clicks the button "New Post", then writes some text (which can contain images and links), and when everything is ready he clicks "Save" button. So we have somehow formatted text mixed with images / video / references to another resources, etc. How should I store blog posts? Is it correct to save html right into the database?

like image 534
experimenter Avatar asked Nov 02 '22 02:11

experimenter


1 Answers

Is it correct to save html right into the database?

Yeah, sure, why not?

I suppose the one problem you might get is that if people use base 64 encoded in-line images they can exceed the maximum document size. This could cause problems.

In terms of text there shouldn't be a problem, 4MB is great enough for the entire works of Shakespeare with some left over.

One proposal, if you allow such things, is to actually use GridFS to store the blog content itself, splitting the content up over (much smaller than 16MB) chunks.

Another option is to just not allow in-line images within blog posts and to say that if a document reaches its maximum size it should be rejected and the user should be told to externally host their images on a CDN or something instead of in-lining them into the HTML.

So yes, I would personally store the HTML straight into the document and disallowed in-line images.

like image 70
Sammaye Avatar answered Nov 09 '22 13:11

Sammaye