Till now, I had believe that the order of keys in query does not matter until I encountered the following case :
Let's say there's a collection with documents and you need to find just one that belongs to a certain group. The following query
will fail to fetch document with an _id
pFkpqenxxbiFFtzrd
. Instead, it will fetch 2SYzj829FKnezgX3b
db.getCollection('Facilities').findOne({_id: "pFkpqenxxbiFFtzrd", _id: {$in: [ '2SYzj829FKnezgX3b', 'pFkpqenxxbiFFtzrd', 'Znsbs5Rzr6DopZmro' ]}})
While this one will do it :
db.getCollection('Facilities').findOne({_id: {$in: [ '2SYzj829FKnezgX3b', 'pFkpqenxxbiFFtzrd', 'Znsbs5Rzr6DopZmro' ]}, _id: "pFkpqenxxbiFFtzrd"})
The question is why?