Is it OK to store HTML in MongoDB? Are there disadvantages? Are there better alternatives?
I'm a bit new to JSON, but I'm planning migrate my WordPress site to a custom meteor/mongodb site.
In WordPress our "Posts" are essentially product records, and the "main content" is the product's description. These descriptions contain some HTML markup, such as "strong" tags, break tags, and href hyperlinks.
<p>Who hasn't wished for a mini-Roomba to handle the arduous task of cleaning their iPhone screen? Now your dreams have come true! See the Takara web page for a <a href="http://www.takaratomy.co.jp/products/automee/" title="automee s" target="_blank">demo video.</a><strong>Colors: </strong> White, Red, Orange and Blue Runs on a single AA battery.<br> 1,575 yen</p>
Unlike XML, JSON lacks something like CDATA. Is it a bad idea to try and put HTML in my JSON-style doc description field? Are there special escape characters for doing this? Or should I store the HTML product description as a external, static file? Or are there other best practices?
{
'_id':'236',
'name':'Tokyo Marui M9A1 Gas Blow Back Airsoft Gun',
'description':'<p>html here?</p>',
'tags': ['toys','outdoors']
...
}
Any tip, advice, links appreciated!
EDIT
Sample product description text added.
EDIT2
I found this stackoverflow article: How to store HTML data in MongoDB?
and another on google https://groups.google.com/forum/?fromgroups=#!topic/mongodb-user/HW5XB5yox20
They seem to say it should be fine. But there isn't much discussion, so just seeking more confirmation.
Edit3
additional reference https://groups.google.com/forum/?fromgroups=#!topic/mongodb-user/0m8KJ7mPWiQ
OK I seem to have found enough articles to conclude:
It's perfectly fine to store html fragments and files in MongoDB as standard utf-8 encoded strings with a few caveats, noted in the MongoDB documentation "when should I use GridFS" (more on GridFS here)
GridFS is a specification for storing and retrieving files that exceed the BSON-document size limit of 16 MB.
ℹ️ NOTE GridFS does not support multi-document transactions.
Instead of storing a file in a single document, GridFS divides the file into parts, or chunks, and stores each chunk as a separate document.
When to use GridFS In MongoDB
In MongoDB, use GridFS for storing files larger than 16 MB. Do not use GridFS if you need to update the content of the entire file atomically.