I have a set of documents that are the same but could be sorted into two distinct groups based on usage.
One of these groups, we'll call them "current", has a low volume of documents being queried a lot.
The other group, we'll call them "backlog", is a huge volume of documents queried much less often.
My thought was that not mixing these these two types of the same document would allow me to query the very active "current" docs without needing to sift through the huge amount of "backlog" every time.
Should these be in two different collections or the same "cars" collection?
mongo.collection('cars', function(err, cars){
cars.find({type:'new', color:'blue'}).toArray(function(err, newBlueCars) {
//do something with newBlueCars
});
});
mongo.collection('cars', function(err, cars){
cars.find({type:'used', color:'blue'}).toArray(function(err, usedBlueCars) {
//do something with usedBlueCars
});
});
OR
mongo.collection('cars.current', function(err, cars){
cars.find({color:'blue'}).toArray(function(err, currentBlueCars) {
//do something with newBlueCars
});
});
mongo.collection('cars.backlog', function(err, cars){
cars.find({color:'blue'}).toArray(function(err, backlogBlueCars) {
//do something with usedBlueCars
});
});
You can index type & color together and get a nice response time, there is no need to seperate them in two collections, it is not a good practice for maintainability. You may need same operations on both, but in this way, you will need to repeat everything twice.
I figured I would post an actual answer, now that it has been sufficiently hashed out in comments (the other answer isn't quite good enough).
The benefits of keeping it all in one collection are:
The downsides of keeping it all in one collection are:
The benefits of splitting them into two collections are:
The downsides of splitting them into two collections are: