java mongodb geo_MongoDB $ geoNear聚合管道(使用查询选项并使用$ match管道操作)给出不同的结果...

我使用$ geoNear作为聚合框架的第一步 . 我需要根据“标签”字段过滤掉结果并且它工作正常,但我发现有两种方法都能给出不同的结果 .

Sample MongoDB Document

{

"position": [

40.80143,

-73.96095

],

"tag": "pizza"

}

我在“位置”键中添加了2dsphere索引

db.restaurants.createIndex( { 'position' : "2dsphere" } )

Query 1

使用$ match聚合管道操作根据“tag”键过滤掉结果

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}}

}

]

);

Query 2

Uses query inside the $geoNear aggregation operation to filter results based on "tag" key

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}}

}

]

);

分组选项只是为了获取两个查询返回的文档数 .

两个查询返回的totalDocs似乎不同 .

有人可以解释我两个查询之间的差异吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值