Saying I have compound _id on collection A:
{
_id:{
orgUnit:Int64
...
}
}
Querying such shows that index is used:
db.A.find({_id:{orgUnit:1039}}).explain()
…
"indexBounds" : {
"start" : {
"_id" : {
"orgUnit" : 1039
}
},
"end" : {
"_id" : {
"orgUnit" : 1039
}
}
But when I changing query to “dot notation” shows that query became plain.
db.A.find({"_id.orgUnit":1039}).explain()
...
"indexBounds" : {
},
What is wrong with dot notation? And the main: How to leverage indexing to allow me find by "_id.orgUnit"
You would need to create a separate index on
'_id.orgUnit'to efficiently query on that field using dot notation.