你的查詢修改其實原因很簡單,只包括了以GeoJSON類型查詢過濾條件:
db.BLR_all.find(
{
"geom" : {
"$geoWithin" : {
"$geometry" : {
"type" : "Polygon",
"coordinates" : [ [ /** array of points **/ ] ]
}
}
},
"geom.type": "Point"
})
或特別對一些樣本數據,
{
"_id" : ObjectId("534cb37acca5f311cc5c23cc"),
"loc" : {
"type" : "Polygon",
"coordinates" : [
[
[
0,
0
],
[
3,
6
],
[
6,
1
],
[
0,
0
]
]
]
}
}
{
"_id" : ObjectId("535aeddfb6b8fd04b3424a09"),
"loc" : {
"type" : "Point",
"coordinates" : [
3,
6
]
}
}
{
"_id" : ObjectId("535aef22b6b8fd04b3424a0a"),
"loc" : {
"type" : "Point",
"coordinates" : [
9,
12
]
}
}
正在發送查詢:
db.geo.find({
"loc": {
"$geoWithin": {
"$geometry": {
"type": "Polygon",
"coordinates": [ [ [ 0, 0 ], [ 3, 6 ], [ 6, 1 ], [ 0, 0 ] ] ]
}
}
},
"loc.type": "Point"
})
只返回屬於「點」且位於座標範圍內的項目。
{
"_id" : ObjectId("535aeddfb6b8fd04b3424a09"),
"loc" : {
"type" : "Point",
"coordinates" : [
3,
6
]
}
}