我有一个包含简单升序索引和地理空间索引的复合索引:
{ v: 1, key: { PlayerSortMask: 1, RandomGeoIdentifier: "2dsphere" }, ns: "JellyDev.Players", name: "Sort Mask + Random Geo ID", min: 0, max: 1 }
现在我遇到以下两个问题:
1。 当我尝试使用前缀索引(仅在第一个索引上查询)时,我得到了一个基本游标,而不是我创建的索引:
使用的查询:
{ "PlayerSortMask" : 2 }
回复说明:
{ "cursor" : "BasicCursor", "isMultiKey" : false, "n" : 1, "nscannedObjects" : 1, "nscanned" : 1, "nscannedObjectsAllPlans" : 1, "nscannedAllPlans" : 1, "scanAndOrder" : false, "indexOnly" : false, "nYields" : 0, "nChunkSkips" : 0, "millis" : 0, "indexBounds" : { }, "allPlans" : [{ "cursor" : "BasicCursor", "n" : 1, "nscannedObjects" : 1, "nscanned" : 1, "indexBounds" : { } }], "server" : "widmore:10010" }
2。 不确定这是否是一个问题,但当我使用两个字段查询时,使用$ eq& $ near,我得到以下解释:
{ "cursor" : "S2NearCursor", "isMultiKey" : true, "n" : 1, "nscannedObjects" : 1, "nscanned" : 6, "nscannedObjectsAllPlans" : 1, "nscannedAllPlans" : 6, "scanAndOrder" : false, "indexOnly" : false, "nYields" : 0, "nChunkSkips" : 0, "millis" : 0, "indexBounds" : { }, "nscanned" : NumberLong(6), "matchTested" : NumberLong(1), "geoMatchTested" : NumberLong(1), "numShells" : NumberLong(3), "keyGeoSkip" : NumberLong(5), "returnSkip" : NumberLong(0), "btreeDups" : NumberLong(0), "inAnnulusTested" : NumberLong(1), "allPlans" : [{ "cursor" : "S2NearCursor", "n" : 1, "nscannedObjects" : 1, "nscanned" : 6, "indexBounds" : { } }], "server" : "widmore:10010" }
这是用于获取结果的查询:
{ "PlayerSortMask" : 2, "RandomGeoIdentifier" : { "$near" : { "$geometry" : { "type" : "Point", "coordinates" : [0.88434365572610107, 0.90583264916475525] } } } }
现在它说它使用了S2NearCursor
,但它显然不是我创建的索引 - 因为它的名称为Sort Mask + Random Geo ID
。
非常感谢任何帮助。
答案 0 :(得分:2)
对于问题1,MongoDB中存在使用复合地理索引的已知问题。 https://jira.mongodb.org/browse/SERVER-9257 该问题在2.5.4中得到修复,这是一个beta版本。
您现在可以通过在PlayerSortMask上创建一个额外的简单索引来解决此问题。
对于问题2,S2NearCursor表示正在使用索引。我认为解释“失去”这个名字,这是一个已知问题,但我记不起错误号了。