I have the next collection sample:
var testSchema = new Schema({
title: {type: String, required: true},
owner: {type:Schema.Types.ObjectId},
locatedAt: {type: {}, index: '2dsphere', sparse: true, "2dsphereIndexVersion": 2, required: true}
});
I inserted 10.000 rows for evaluate the schema performance
db.test.find({"locatedAt":{"$near":{"$geometry":{"type":"Point","coordinates":[2.240413,41.582159]}}}}).explain();
The result is the next one:
{
"cursor" : "S2NearCursor",
"isMultiKey" : false,
"n" : 10000,
"nscannedObjects" : 48846,
"nscanned" : 48846,
"nscannedObjectsAllPlans" : 48846,
"nscannedAllPlans" : 48846,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 95,
"indexBounds" : {
},
"filterSet" : false
}
I tried creating a "2d" index with the same result.
Summarizing in my opinion the query is scanning too much rows, what I'm doing wrong? Maybe the Schema definition?
Thank you!!