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似乎有所不同。
有人可以解释我两个查询之间的区别吗?