Mongo db - storing media in documents and performance Mongo db - storing media in documents and performance mongoose mongoose

Mongo db - storing media in documents and performance


You don't have to retrieve all the information. You can use projection to just get back, say, the username and email

> db.collection.find(<query condition>, { "username" : 1, "email" : 1, "_id" : 0 })

This sends less information from the server to the client but you do still have to load the whole document into memory in the server, which may or may not be important for you. If the binary info is large, like for high res images, keep in mind there's a strict 16mb limit on documents in MongoDB. In that case, you should look into using GridFS to store the images.


In our real world scenarios that does not consist of processing and making changes to the media content, this decision was primarily driven by the need for extensibility and maintainability which effect performance indirectly - storing images or documents in mongodb has substantial overheads associated with supporting data fidelity (multiple formats and size variations of data depending on the requestor) and data archiving (defunct accounts, expired data, etc.). Here are the short list of key reasons that drove our decision of selecting file systems over mongodb in these scenarios:

  • Better support for data fidelity
  • Easy maintenance and archiving
  • Cheaper file storage
  • Better DB cache utilization
  • Better DB query performance for find
  • Better memory utilization of DB instances
  • Ability to incorporate query memoization within our application
  • Reduction in programming errors due to query complexity