【发布时间】:2018-02-26 19:09:03
【问题描述】:
我的数据库看起来像
{
"_id" : ObjectId("5a8351093cf24e144d8fef24"),
"__type" : "TrafficIncident:http://schemas.microsoft.com/search/local/ws/rest/v1",
"point" : {
"type" : "Point",
"coordinates" : [
37.410883,
-95.71027
]
},
...
}
{
"_id" : ObjectId("5a8351093cf24e144d8fef25"),
"__type" : "TrafficIncident:http://schemas.microsoft.com/search/local/ws/rest/v2",
"point" : {
"type" : "Point",
"coordinates" : [
40.2346,
-100.826167
]
},
...
}
如果我有一个坐标对作为中心位置,比如 [38, -98],并且我想检索坐标范围 [38 +- 2, -98 +- 2] 内的所有记录,如何编写 java 代码用于文档过滤器?
到目前为止,我所做的是检索特定位置而不是范围内。
Document query = new Document("point.coordinates", Arrays.asList(40.2346, -100.826167));
javamongo.collection.find(query).limit(javamongo.numLimit).forEach(printBlock);
【问题讨论】:
标签: java mongodb filter documentfilter