使用 Polygons 和 Mongoose 进行地理空间查询有什么问题?
我正在使用 $polygon
搜索进行地理空间查询。我的查询是:
{
'location_latLong': {
'$within': {
'$polygon': {
point1: {
lon: '-74.2621',
lat: '40.5788'
},
point2: {
lon: '-74.2621',
lat: '40.8494'
},
point3: {
lon: '-73.7499',
lat: '40.8494'
},
point4: {
lon: '-73.7499',
lat: '40.5788'
}
}
}
}
}
在我的集合中,我有一个文档明显位于多边形内:
{
"_id": ObjectId("4e95c285cb8a0efc2b00001a"),
"addedOn": Date(1318437509839),
"checkinDate": Date(1318392000000),
"checkinTime": Date(1318437476000),
"location_city": "New York",
"location_country": "United States",
"location_latLong": {
"xLon": -74.007124,
"yLat": 40.71455
},
"location_source": "personprofile",
"location_state": "New York",
"location_zip": ""
}
并且我在 location_latLong
上有一个 2d
索引。我知道 MongoDB 会忽略键名(据说),所以这应该不重要。那么为什么会返回 0 结果呢?
编辑 我刚刚按照评论中的建议运行了一个 explain
,我得到:
{
"cursor" : "GeoBrowse-polygon",
"nscanned" : 0,
"nscannedObjects" : 0,
"n" : 0,
"millis" : 0,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
"location_latLong" : [
[
[
0,
0
],
[
0.000021457672119140625,
0.000021457672119140625
]
],
[
[
-0.000021457672119140625,
-0.000021457672119140625
],
[
0,
0
]
],
[
[
-0.000021457672119140625,
0
],
[
0,
0.000021457672119140625
]
],
[
[
0,
-0.000021457672119140625
],
[
0.000021457672119140625,
0
]
]
]
},
"keysChecked" : NumberLong(8),
"lookedAt" : NumberLong(4),
"matchesPerfd" : NumberLong(0),
"objectsLoaded" : NumberLong(0),
"pointsLoaded" : NumberLong(0)
}
I'm doing a geospatial query using a $polygon
search. My query is:
{
'location_latLong': {
'$within': {
'$polygon': {
point1: {
lon: '-74.2621',
lat: '40.5788'
},
point2: {
lon: '-74.2621',
lat: '40.8494'
},
point3: {
lon: '-73.7499',
lat: '40.8494'
},
point4: {
lon: '-73.7499',
lat: '40.5788'
}
}
}
}
}
In my collection, I have a document that CLEARLY lies within the polygon:
{
"_id": ObjectId("4e95c285cb8a0efc2b00001a"),
"addedOn": Date(1318437509839),
"checkinDate": Date(1318392000000),
"checkinTime": Date(1318437476000),
"location_city": "New York",
"location_country": "United States",
"location_latLong": {
"xLon": -74.007124,
"yLat": 40.71455
},
"location_source": "personprofile",
"location_state": "New York",
"location_zip": ""
}
and I have a 2d
index on location_latLong
. I know that MongoDB ignores key names (supposedly), so that shouldn't matter. So why does this return 0 results?
EDIT
I just ran an explain
as recommended in the comments and I get:
{
"cursor" : "GeoBrowse-polygon",
"nscanned" : 0,
"nscannedObjects" : 0,
"n" : 0,
"millis" : 0,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
"location_latLong" : [
[
[
0,
0
],
[
0.000021457672119140625,
0.000021457672119140625
]
],
[
[
-0.000021457672119140625,
-0.000021457672119140625
],
[
0,
0
]
],
[
[
-0.000021457672119140625,
0
],
[
0,
0.000021457672119140625
]
],
[
[
0,
-0.000021457672119140625
],
[
0.000021457672119140625,
0
]
]
]
},
"keysChecked" : NumberLong(8),
"lookedAt" : NumberLong(4),
"matchesPerfd" : NumberLong(0),
"objectsLoaded" : NumberLong(0),
"pointsLoaded" : NumberLong(0)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我解决了这个问题。我正在传递字符串,我应该传递浮点数。
感谢您的宝贵时间=)
I solved the problem. I was passing Strings and I should have been passing floats.
Thanks for your time =)