1
我正在使用$ geoNear作爲聚合框架中的第一步。我需要根據「標記」字段篩選出結果,它工作正常,但我看到有兩種方法給出不同的結果。
樣品的MongoDB文獻
{ "position": [ 40.80143, -73.96095 ], "tag": "pizza" }
我已經加入2dsphere索引的 「位置」 鍵
db.restaurants.createIndex({ 'position' : "2dsphere" })
查詢1
db.restaurants.aggregate( [ { "$geoNear":{ "near": { type: "Point", coordinates: [ 55.8284,-4.207] }, "limit":100, "maxDistance":10*1000, "distanceField": "dist.calculated", "includeLocs": "dist.location", "distanceMultiplier":1/1000, "spherical": true } },{ "$match":{"tag":"pizza"} }, { "$group":{"_id":null,"totalDocs":{"$sum":1}} } ] );
查詢2
db.restaurants.aggregate( [ { "$geoNear":{ "query" : {"tag":"pizza"} "near": { type: "Point", coordinates: [ 55.8284,-4.207] }, "limit":100, "maxDistance":10*1000, "distanceField": "dist.calculated", "includeLocs": "dist.location", "distanceMultiplier":1/1000, "spherical": true } }, { "$group":{"_id":null,"totalDocs":{"$sum":1}} } ] );
分組選項僅用於g以及這兩個查詢返回的文檔的數量。
這兩個查詢返回的totalDocs似乎有所不同。
有人可以解釋我兩個查詢之間的區別嗎?