【发布时间】:2017-05-31 09:22:07
【问题描述】:
我在记录集合 Mongodb (3.4) 中有文档,如下所示:-
{
"_id" : ObjectId("592d0c78555a7436b0883960"),
"userid" : 7,
"addresses" : [
{
"apporx" : 50.0,
"loc" : [
-73.98137109999999,
40.7476039
]
},
{
"apporx" : 15.0,
"loc" : [
-73.982002,
40.74767
]
},
{
"apporx" :10.0,
"loc" : [
-73.9819567,
40.7471609
]
}
]
}
`
I created index on this collection using below query :-
`db.records.createIndex({'addresses.loc':1})`
when i execute my below query :-
`db.records.aggregate(
{$geoNear : {
near : [ -73.9815103, 40.7475731 ],
distanceField: "distance"
}});
这个结果给了我距离字段。现在你能在我的文档中解释一下这个多个元素中存在哪个地址数组吗?我怎样才能确定这个结果对于哪个元素是正确的?
另一个问题:- 如果我在“addresses.apporx”上设置条件大于或等于,那么有什么方法可以找到这个条件的位置吗?
【问题讨论】:
标签: mongodb geolocation mongodb-query aggregation-framework