环回:对象子字段上的过滤器附近 [英] Loopback: near filter on object sub-field
问题描述
我有一个这样的模型:
{
name: 'My Favorite Shop',
address:{
location: [12.534 /* longitude */ ,41.9221/* latitude */]
}
}
文档存储在mongodb数据库中,因此我想像这样查询它们:
Documents are stored in a mongodb database, and thus I'd like to query them like:
//assuming shops to be the name of the containing model
app.models.shops.find({
where: {
'address.location': {lat: 13, lng: 40}
}
}, callback);
问题是此查询不会检索任何结果.我想这是由于location
字段的性质所致,该字段嵌套在address
中,但是我无法验证这一点.
Problem is this query would not retrieve any result. I guess it's because of the nature of location
field, which is nested into address
, but I couldn't verify that.
有什么主意吗?
谢谢
更新:
结果我忘了在数据源定义中设置enableGeoIndexing
属性.完成后,查询将检索以下错误:
UPDATE:
it came out I forgot to set the enableGeoIndexing
property in datasource definition. Once done, the query is retrieving the following error:
{"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}
推荐答案
我终于找到了问题所在.在address.location
字段上应用了2d
索引,但是环回(似乎)仅支持通过2dSphere
索引进行地理查询.因此,我通过在此类字段上添加2dSphere
索引来解决.
I finally found the problem. A 2d
index was applied on the address.location
field, but Loopback (seems to) only support geoquery over 2dSphere
indexes. Thus, I solved by adding a 2dSphere
index over such field.
这篇关于环回:对象子字段上的过滤器附近的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!