[英]Get all items withing a bounding box in MongoDB
I've a problem with a query matching items inside a BoundingBox. 查询与BoundingBox中的项目匹配时出现问题。 I've read in the mongo documentation a lot without success about
$box
and $geoWithin
but can't figure out why the item which is inside the queried box is not resulting. 我已经在mongo 文档中阅读了很多有关
$box
和$geoWithin
但都没有成功,但是无法弄清楚为什么没有生成所查询的盒子中的项目。
Here an example from defined Schema over an Item inside and the Query to get it out 这里有一个示例,该示例来自定义在内部项目上的模式以及将其取出的查询
The schemadefinition looks like this and it's validation is working. schemadefinition看起来像这样,它的验证正在起作用。
/**
* Media location values (Point, LineString, Polygon)
* @property location
* @type {Object}
*/
location:{
"type":Object,
"index":"2dsphere"
},
One item inside looks like this (which is expected as a result of the query): 里面的一项看起来像这样(这是查询的结果):
{
"_account": "52796da308d618090b000001",
"_id": "5280d9c6592dce2d36000001",
"location": {
"coordinates": [
50.109230555555555,
8.757613888888889
],
"type": "Point"
},
"name": "Büro",
"preview": "/img/thumbs/13869-2gqv8n.JPG",
"type": "image/jpeg",
"added": "2013-11-11T13:21:10.951Z",
"latlng": [ ],
"shares": [ ],
"shared": false,
"tags": [ ]
}
The query to fetch the item looks like 查询以获取项目看起来像
{
// tried also "location.coordinates" without luck
"location": {
" $geoWithin": {
"$box": [
[
49.99825021043669,
8.543586730957031
],
[
50.139285461134996,
8.996772766113281
]
]
}
}
}
Whats wrong here to get always en empty array as result? 为了始终得到空数组,这里出了什么问题?
I can see one thing that is wrong here. 我在这里看到一件错误的事情。 Shouldnt
" $geoWithin"
be "$geoWithin"
?? 不应该将
" $geoWithin"
设为"$geoWithin"
?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.