我在2dsphere上索引了loc字段,但无法在Point类型的GeoJson数据上运行geowithin查询。
以下是查询:
db.test.find( { loc :
{ $geoWithin :
{ $geometry :
{ type : "Polygon" ,
coordinates : [ [ [-74.6862705412253, 40.42341005] ,
[-75.0846179, 39.9009465 ],
[-74.20570119999999, 41.0167639 ]
]
]
}
}
}
}
输出:
uncaught exception: error: {
"$err" : "Can't canonicalize query: BadValue bad geo query",
"code" : 17287
}
文档结构:
{
"_id" : ObjectId("53d15e7132e7b7978c472e6e"),
"loc" : {
"type" : "Point",
"coordinates" : [ -74.6862705412253, 40.42341005 ]
},
}
索引:
{
"0" : {
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "collab.test"
},
"1" : {
"v" : 1,
"key" : {
"loc" : "2dsphere"
},
"name" : "TestLocationIndex",
"ns" : "collab.test",
"2dsphereIndexVersion" : 2
}
但是,$Polygon在相同的文档上运行良好。我正在尝试理解为什么geowithin不起作用?