Hi Olivier,
What you are observing is a bug described in JIRA ticket SERVER-22448, where the query planner does not filter 2dsphere index version 3 correctly. This bug was fixed in v3.2.3.
Due to the sparse property of 2dsphere index version 3, in order for the query planner to use a compound index that includes a 2dsphere you need to also specify the 2dsphere index field. For example :
db.foo.find({
"_id.time":{$gt:ISODate("20160320")},
"loc": {
"$near": {
"$geometry":{
"type":"Point",
"coordinates":[-37.5215, 48.7531]
},
"$maxDistance":1000
}
}
}
}).explain()
Since the database contains tens of millions, the use of indexes is mandatory.
I would recommend to create a separate index for _id.time if you perform queries without the loc field often.
Regards,
Wan.