我在 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 不起作用?