Storing 2000+ fields in a document

39 views
Skip to first unread message

Mayur Tanna

unread,
May 6, 2016, 4:06:11 AM5/6/16
to mongodb-user
Hello,

I have a model field with more than 2000+ fields in my application. I am using mongodb as a database. What will be the efficient way to store documents with 2000+ number of fields in it ? Is it fine if I store it in a single collection ? or should I make smaller collections to store a few fields in each collection?

Thanks. 
Message has been deleted

Chris Cunningham

unread,
May 24, 2016, 7:08:12 AM5/24/16
to mongodb-user

Mayur,


It is possible to create a collection with documents that contain 2000+ fields, however it is highly recommended that you perform an analysis of your data to ensure that you do not exceed the limit of 16mb for the BSON file. For further information on the sizing limits and thresholds, please review MongoDB Limits and Thresholds.


You may also find the following links helpful: 


Indexing and other limits concerning indexes
A collection can have at most 64 indexes.
A collection can only have one multikey index (i.e. index on an array field).
A collection can only have one text index.
A compound index can have no more than 31 fields.


Please note that each operation that mutates the collection (e.g. insert, update, delete) will have to write to the indexes as well if the operation changes an indexed field.


In regards to your efficiency question, efficiency is highly use-case specific and typically involves a balance between maintainability and usability that you find acceptable for your specific case. For example, in a 2000+ fields document, a single read would have to transmit all of the fields. If the application does not need all 2000+ fields all the time, then you are transmitting irrelevant data that will just be discarded upon receipt. On the other hand, if the 2000+ fields belong to a single entity and you are using multiple collections to represent this entity, then updating one entity will involve writing to many different collections at once, which may complicate your application code.


You may find the following resources helpful in this regard:

▪ MongoDB data modeling: https://docs.mongodb.com/manual/data-modeling/
▪ Use cases: https://docs.mongodb.com/ecosystem/use-cases/
▪ 6 Rules of Thumb for MongoDB Schema Design: Part 1, Part 2, and Part 3


Please let us know if you have any further questions.


Regards,


Chris

Reply all
Reply to author
Forward
0 new messages