我有下一个收集样本:
var testSchema = new Schema({
title: {type: String, required: true},
owner: {type:Schema.Types.ObjectId},
locatedAt: {type: {}, index: '2dsphere', sparse: true, "2dsphereIndexVersion": 2, required: true}
});
我插入了 10.000 行来评估架构性能
db.test.find({"locatedAt":{"$near":{"$geometry":{"type":"Point","coordinates":[2.240413,41.582159]}}}}).explain();
结果是下一个:
{
"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
}
我尝试创建一个具有相同结果的“2d”索引。
总结我认为查询正在扫描太多行,我做错了什么?也许是模式定义?
谢谢!!