【发布时间】:2018-09-06 14:40:03
【问题描述】:
我正在尝试查找符合我的条件的社区 - boundries 多边形与帖子的坐标相交,但我无法做到 - 无法在我的 pipeline $match 中使用 let
帖子实体示例:
{
_id: ObjectId,
...,
location: {
...,
coordinates: {
type: 'Point',
coordinates: [number, number]
}
}
};
社区实体示例:
{
_id: ObjectId,
...,
boundries: {
type: 'Polygon',
coordinates: [ [ [number, number], [number, number], [number, number], [number, number], [number, number] ] ]
}
};
我正在尝试“修复”的查询示例:
db.posts.aggregate([
{ $match: { _id: ObjectId('5a562e62100338001218dffa') } },
{
$lookup: {
from: 'neighborhoods',
let: { postCoordinates: '$location.coordinates.coordinates' },
pipeline: [
{
$match: {
boundries: {
$geoIntersects: {
$geometry: {
type: 'Point',
coordinates: '$$postCoordinates'
}
}
}
}
}
],
as: 'neighborhoods'
}
}
]);
【问题讨论】:
-
您能否详细说明您面临的具体错误。
-
对于使用
let,你可以看到https://stackoverflow.com/questions/48518215/mongodb-aggregation-lookup-with-conditions可能对你有帮助
标签: mongodb mongodb-query aggregation-framework