【发布时间】:2014-09-24 20:10:42
【问题描述】:
我有下一个收集样本:
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”索引。
总结一下,我认为查询扫描了太多行,我做错了什么?也许是模式定义?
谢谢!!
【问题讨论】:
-
对于地理索引,nscanned* 数字不是文档。它们代表了地理索引内部的一些东西,这不一定很重要 - 重要的是这个数字仍然与工作量成正比,所以它可以用来比较地理查询。报告的获取所有 10000 个文档的时间是 95 毫秒,所以我认为查询执行得很好(注意:一般来说,在解释中实际上不要使用 millis 字段来获取时间信息)。
-
感谢您的评论。我今天继续评估信息(学习“解释”字段的含义),如果您包含限制或约束,则 nscanned 数据是正确的,而 milis 变为 4。所以,这只是对 find 的错误利用,这不是架构定义的过滤器的问题。
标签: mongodb mongodb-indexes 2dsphere