Mongodb – Should images be separated from posts in MongoDb

mongodb

I am working on a project with Meteor.js and I am using CollectionFS with GridFS to easily store images in MongoDb. Now I am not the best with databases and database design, but I heard that in nosql database you should try to denormalize data. So to my real question, what is preferred?

One:

An Images collection and then a Posts Collection with a corresponding imageId?

Only a Posts Collection(FS.Collection) and then save the image along with title, etc?

I feel like this is stupid, but somehow I think they should be separated.

Best Answer

You feel like they should be separated because that makes perfect sense in the relational world.
But as you said in the NoSql world and in MongoDB in particular, you want to group like-items together. I've not done extensive research on Mongo, but have spent some time with the online classes and I believe the answer is to store them together. You probably realize there is no such thing as a join in Mongo and therefore if you wanted to get 100 rows and get their corresponding images, you'd have to get the IDs for the 100 rows and then get 100 rows by their identifier (object_id or whatever). In other words, you have to do manual joins.