You can use embedded documents to get all the required data in a single query call. As a solution for this scenario, if your application heavily relies on joins then denormalizing schema makes more sense. This will obviously require more time as it involves the network. If you are retrieving data from multiple collections and joining a large amount of data, you have to call DB several times to get all the necessary data. Therefore, we have to get all the data from DB and then perform join at the application level. Try to Avoid Application-Level JoinsĪs we all know, MongoDB doesn’t support server level joins.
This will trigger an in-place update in memory, hence improved performance. Instead of updating the whole document, you can use field modifiers to update only specific fields in the documents. This can drastically degrade the write performance of your database. If you try to update the whole document, MongoDB will rewrite the whole document elsewhere in the memory. In case, your application needs to store documents of size more than 16 MB then you can consider using MongoDB GridFS API. You can use document buckets or document pre-allocation techniques to avoid this situation. It can lead to failure of queries sometimes. If your document size increases more than 16 MB over a period of time then, it is a sign of bad schema design. By default, MongoDB allows 16MB size per document. If your schema allows creating documents which grow in size continuously then you should take steps to avoid this because it can lead to degradation of DB and disk IO performance. Here are some points which you can consider while designing your schema. In this article, I will discuss some general tips for planning your MongoDB schema.įiguring out the best schema design which suits your application may become tedious sometimes. In short, “Schemaless” doesn’t mean you don’t need to design your schema. This is beneficial for the initial stages of development but in the later stages, you may want to enforce some schema validation while inserting new documents for better performance and scalability. Normally, MongoDB stores documents in a JSON format so each document can store various kinds of schema/structure. This means that MongoDB does not impose any schema on any documents stored inside a collection. One of the most advertised features of MongoDB is its ability to be “schemaless”.