What's wrong with Geospatial queries using Polygons and Mongoose?
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" :开发者_JAVA百科 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 solved the problem. I was passing Strings and I should have been passing floats.
Thanks for your time =)
精彩评论