首页 > 解决方案 > MongoDB 的 $lookup 中的 $geoWithing

问题描述

我正在寻找查询以在其他集合的查找中创建 $geoWithin。

我实际上拥有的是:

db.getCollection('polygons').aggregate([{ 
    $lookup: {
        from: "coll1",
        let: { geometry_poly: "$geometry" },
        pipeline: [
            { $match: { "location": { $geoWithin: { $geometry: "$$geometry_poly" } } } },
            { $project: { name: "$hashtag" } }
        ],
        as: "PolyAvg"
    }
}])

科尔1:

{
    "_id" : ObjectId("5e90bf7b49ebb0e6b459a00f"),
    "hashtag" : "stayhome",
    "timestamp" : ISODate("2020-04-10T18:48:25.876Z"),
    "location" : {
        "type" : "Point",
        "coordinates" : [ 
            14.421425, 
            40.26084
        ]
    },
}

多边形:

{
    "_id" : ObjectId("5e95d56e49ebb0e6b45a34c4"),
    "type" : "Feature",
    "geometry" : {
        "type" : "Polygon",
        "coordinates" : [ 
            [ 
                [ ... , ... ]
            ]
        ]
    }
}

当我执行此操作时,它总是说 $$geometry_poly 无效

标签: mongodbaggregation-framework

解决方案



推荐阅读