Should two similar data types with different use cases be stored in the same collection?
We have two very similar data types that are both "users". The first one consists of active users and the other has users that are automatically extracted and pulled into our system and have a much lower priority (in terms of speed of access) than active users.
Every active user has the potential to bring in at least 1000 data-mined users. We'll be using the active users much more frequently and performance is our primary concern. Wit开发者_运维知识库h the data-mined users, performance is secondary but we will be storing large quantities of them.
Any input on how we should be handling this? Either one collection for every user (both active and data-mined), or two collections (one for active, one for data-mined users)?
Mongo is great for storing similar, but different, objects in the same collection as long as your app can handle it.
Are the data-mined users a child of the active users? If so, then you would probably want to keep them embedded in the active users documents. You dont need to access them all the time - MongoDB allows you to fetch parts of a document if you dont need the whole thing.
Will you be querying them differently? If so, you may want to keep them separate so that your indexes do not become bloated.
Will you be querying either of them with queries that will not hit indexes? If so you will want to separate them so that you dont need to do full collection scans every time.
精彩评论