【发布时间】:2013-11-13 00:23:38
【问题描述】:
我在查询匹配 BoundingBox 内的项目时遇到问题。
我已经在 mongo documentation 中阅读了很多关于 $box 和 $geoWithin 的内容但没有成功,但无法弄清楚为什么查询框中的项目没有得到结果。
这里是一个示例,来自定义的架构,其中包含一个项目和查询以将其取出
架构定义看起来像这样,它的验证正在工作。
/**
* Media location values (Point, LineString, Polygon)
* @property location
* @type {Object}
*/
location:{
"type":Object,
"index":"2dsphere"
},
里面的一个项目看起来像这样(这是查询的结果):
{
"_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": [ ]
}
获取项目的查询看起来像
{
// tried also "location.coordinates" without luck
"location": {
" $geoWithin": {
"$box": [
[
49.99825021043669,
8.543586730957031
],
[
50.139285461134996,
8.996772766113281
]
]
}
}
}
结果总是空数组有什么问题?
【问题讨论】:
标签: javascript mongodb mongoose geojson