I’m working with mongodb, I’m wondering that if my data (like product data) has several billion records (each record has ~100 fields), should I split that product collection into multiple collections (like ProductCollection1, ProductCollection2, …). When I query data, I know exactly which collection needs to be queried. And this collection is not related to any other collection.
How many documents should there be in 1 collection in mongodb?
2
Answers
In MongoDB, the number of documents you can store in a collection depends on various factors such as the size of the documents, your hardware configuration, and the workload patterns. However, there’s no hard limit on the number of documents you can have in a collection. MongoDB can handle collections with billions of documents efficiently if the infrastructure is appropriately set up.
Regarding splitting your product data across multiple collections, MongoDB has a flexible schema design that allows you to manage large amounts of data within a single collection efficiently
MongoDB has a maximum document size of 16 megabytes.Ensure documents don’t exceed the 16MB limit and are logically grouped.
The design of your collections should take into account your access patterns. How are you looking to query or use this data?
To your question of how many documents a collection can hold, the sky is the limit. The primary mechanism of scaling a MongoDB cluster is horizontally via the concept of sharding. This involves partitioning your data onto several machines.