我已经使用mongodb“2d”索引将我的旧集合转换为具有geojson规范“2dsphere”索引的集合。问题在于查询大约需要11秒才能收集大约2个lac对象。以前是需要大约100毫秒的查询。我的文档如下。Mongodb 2.4 2dsphere查询很慢
{ "_id": ObjectId("4f9c2aa2d142b9882f02a3b3"), "geonameId": NumberInt(1106542), "name": "Chitungwiza", "feature code": "PPL", "country code": "ZW", "state": "Harare Province", "population": NumberInt(340360), "elevation": "", "timezone": "Africa\/Harare", "geolocation": { "type": "Point", "coordinates": { "0": 31.07555, "1": -18.01274 } } }
我解释查询的输出如下。
db.city_info.find({"geolocation":{'$near':{ '$geometry': { 'type':"Point",coordinates:[73,23] } }}}).explain()
{
"cursor" : "S2NearCursor",
"isMultiKey" : true,
"n" : 172980,
"nscannedObjects" : 172980,
"nscanned" : 1121804,
"nscannedObjectsAllPlans" : 172980,
"nscannedAllPlans" : 1121804,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 13,
"nChunkSkips" : 0,
"millis" : 13841,
"indexBounds" : {
},
"nscanned" : 1121804,
"matchTested" : NumberLong(191431),
"geoMatchTested" : NumberLong(191431),
"numShells" : NumberLong(373),
"keyGeoSkip" : NumberLong(930373),
"returnSkip" : NumberLong(933610),
"btreeDups" : NumberLong(0),
"inAnnulusTested" : NumberLong(191431),
"server" : "..."
}
请让我知道如何解决问题并缩短查询时间。
$ near不需要$ maxDistance。您执行的查询已成功并正确地返回了您要求的内容。 – 2013-07-08 17:02:21