{
"accountId": "...",
"buildingId": {
"$in": [
"...",
// 50 more
]
},
"created": { "$gte": ISODate(...), $lt: ISODate(...) },
}
I have an index for:
{ accoundId: 1, buildingId: 1, created: 1}
and for:
{ accoundId: 1, created: 1}
I noticed when I get too many $in elements, it will switch from the more specific index, to the more generic one. The explain:
"planSummary": "IXSCAN { accountId: 1, created: -1 }",
"keysExamined": 34810,
"docsExamined": 34810,
"cursorExhausted": true,
"numYields": 43,
"nreturned": 29,
"queryHash": "E8C5EB6E",
"planCacheKey": "6E1958CA",
"reslen": 11692,
"locks": {
"ReplicationStateTransition": {
"acquireCount": {
"w": 51
}
},
"Global": {
"acquireCount": {
"r": 51
}
},
"Database": {
"acquireCount": {
"r": 51
}
},
"Collection": {
"acquireCount": {
"r": 51
}
},
"Mutex": {
"acquireCount": {
"r": 8
}
}
},
"storage": {
"data": {
"bytesRead": 28065577,
"timeReadingMicros": 23823
}
},
"protocol": "op_msg",
"durationMillis": 1835,
"v": "4.4.10"