Consider the following data structure in a collection:
{
_id : ObjectId("4ec6c015482c4c8302000001"),
uid : ObjectId("4ec6c015482c4c8302003233") //reference to user's Object ID
someValue : some json object,
}
Said collection will be sharded on uid.
Between these two situations, which would be more performant for reads?
Option A)
Store References to each data structure in the users object and perform this query:
db.collection.find({_id: {$in: ids}}
Option B)
Create an index on uid and query this way:
db.collection.find({uid : ObjectId("4ec6c015482c4c8302003233")})
each result set will include 0-20 of the data structures from the collection.
Summed up: Will it be faster to find() 20 specific ID's or all objects that match an indexed ID value (the result set is also 20)