Boy*_*ral 5 mongodb mongodb-query aggregation-framework geonear
我想通过应用以下过滤器进行 mongodb 查询来搜索公司。
{
myLocation: [lng1, lat1], // That is to get distance from current location to companies on result.
region: [lng2, lat2], //That is to get companies within a radius in this region
radius: 10000,
tags: ["tag1", "tag2"],
sort: "asc" // to sort by nearest from current location.
}
Run Code Online (Sandbox Code Playgroud)
我认为它需要使用 $geoNear 两次并进行这样的聚合。
{
$geoNear: {
near: {
type: "Point",
coordinates: myLocation
},
distanceField: 'distance1',
maxDistance: radius,
spherical: true,
},
$match: { tags: tags },
$geoNear: {
near: {
type: "Point",
coordinates: region
},
distanceField: 'distance2',
spherical: true,
}
}
Run Code Online (Sandbox Code Playgroud)
但它会发生错误 - $geoNear 仅作为管道中的第一阶段有效。
有什么方法可以进行查询来使用此过滤器。
感谢你的帮助。
归档时间: |
|
查看次数: |
89 次 |
最近记录: |