【发布时间】:2017-10-27 02:09:24
【问题描述】:
在聚合管道中使用 $geoNear 时,我没有得到正确的返回结果。使用典型 find() 查询(使用 $near)的相同查询实际上返回了正确的结果。
但是,当删除相等条件时(schedule.key),两个查询都返回正确的数据。
$geoNear 使用聚合管道:
db.place.aggregate(
[
{
$geoNear: {
spherical: true,
near: { type: "Point", coordinates: [ 18.416145, -33.911973 ] },
distanceField: "dist"
}
},
{
$match: {
"schedule.key": { "$eq": "vo4lRN_Az0uwOkgBzOERyw" }
}
}
])
$near查找查询:
db.place.find(
{
"point" : {
$near: {
type: "Point",
coordinates: [ 18.416145,-33.911973 ]
}
},
"schedule.key" : {
$eq : "vo4lRN_Az0uwOkgBzOERyw"
}
})
此集合中的文档如下所示:
{
"_id" : UUID("da6ccbb1-3c7a-45d7-bc36-a5e6007cd919"),
"schedule" : {
"_id" : UUID("587de5b7-a744-4b28-baa8-e6efb5f7f921"),
"key" : "vo4lRN_Az0uwOkgBzOERyw"
},
"point" : {
"type" : "Point",
"coordinates" : [
18.425102,
-33.922153
]
},
"name" : "Cape Town"
}
我已经在点字段上创建了适当的索引:
db.place.ensureIndex( { "point" : "2dsphere" } );
【问题讨论】:
标签: mongodb mongodb-query aggregation-framework