环回:对象子字段上的近过滤器

Loopback: near filter on object sub-field

我有这样一个模型:

{
    name: 'My Favorite Shop',
    address:{
         location: [12.534 /* longitude */ ,41.9221/* latitude */]
    }
}

文档存储在 mongodb 数据库中,因此我想像这样查询它们:

//assuming shops to be the name of the containing model
app.models.shops.find({
    where: {
        'address.location': {lat: 13, lng: 40}
    }
}, callback);

问题是此查询不会检索任何结果。我猜这是因为 location 字段的性质,它嵌套在 address 中,但我无法验证。

有什么想法吗?

谢谢

更新: 结果我忘了在数据源定义中设置 enableGeoIndexing 属性 。完成后,查询将检索以下错误:

 {"name":"MongoError","message":"Unable to execute query: error processing query: ns=acidata-dev.pos limit=25 skip=0\nTree: GEONEAR  field=address.location maxdist=1.79769e+308 isNearSphere=0\nSort: {}\nProj: {}\n planner returned error: unable to find index for $geoNear query","$err":"Unable to execute query: error processing query: ns=acidata-dev.pos limit=25 skip=0\nTree: GEONEAR  field=address.location maxdist=1.79769e+308 isNearSphere=0\nSort: {}\nProj: {}\n planner returned error: unable to find index for $geoNear query","code":17007}

终于找到问题了。 2d 索引应用于 address.location 字段,但 Loopback(似乎)仅支持对 2dSphere 索引的地理查询。因此,我通过在此类字段上添加 2dSphere 索引来解决。