如何查询点是否在圆形架构_猫鼬内

阿巴德海尔分会

这是我的架构:

var schema = new Schema({
    loc: {
        type: {
            type: String
        },
        coordinates: []
    },
     radius : {
      type : 'Number'
     }
});
schema.index({
    loc: '2dsphere'
});
var A = mongoose.model('Circle', schema);

这是我的收藏示例:

{
 loc: {type : "Point", coordinates: [77.69866, 13.025621]}, radius: 100.21
}

我的问题是:是否可以检查这个点[12.1222, 29.2112]是否在我的 Circle 集合内?

一种可能的解决方案是使用$geoNear聚合阶段。

Model.aggregate([
    {$geoNear: {
        near: {type:"Point", coordinates:[12.1222, 29.2112]},
        distanceField: "distance"
    }},
    {$match: {
       $expr: {$lt: ["$distance", "$radius"]}
    }}
])

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章