Actually, without a sort operation attached, they will be returned in natural order.
In general, if you need to have them returned in a specific order, you should state this explicitly:
db.collection.find({"_id":{"$in":["a","b","c"]}}).sort({_id:1});
Which should give you the result set in order a,b,c (assuming that you have a match for all of the queried _id
s). And it is even cheap, since it will make use of an index.
Speaking about indexing: If you sort by another field, there should be an index incorporating that field. So if you have a query like
db.collection.find({"_id":{"$in":["a","b","c"]}}).sort({foo:-1});
There should be an index created like
db.collection.createIndex({_id:1,foo:-1})
MongoDB Mantra of the day
Order matters.
In this case, even twice: The sort order and the order of the keys within the index, which needs to reflect the order of the keys in the query.