我在我的地方收藏了下面的行。
{ "_id" : ObjectId("572b3892967c76c62b7f63e3"), "loc" : { "type" : "Point", "coordinates" : [ -73.97, 40.77 ] }, "name" : "Central Park", "category" : "Parks" }
{ "_id" : ObjectId("572b38ba967c76c62b7f63e4"), "loc" : { "type" : "Point", "coordinates" : [ -73.88, 40.78 ] }, "name" : "La Guardia Airport", "category" : "Airport" }我无法执行以下查询
db.places.find({$nearSphere: {$geometry: { type: "Point", coordinates: [-73.92, 40.775]}, $minDistance: 10000, $maxDistance: 10}})我得到以下错误:Error: error: { "$err" : "Can't canonicalize query: BadValue unknown top level operator: $nearSphere", "code" : 17287 }
请告诉我是怎么回事。
发布于 2016-05-06 06:37:42
在查询对象中,缺少"loc“字段。此外,我认为您声明了minDistance和maxDistance错误,因为maxDistanace < minDistance。
我认为您想要的查询如下:
db.places.find({loc:{$nearSphere: {$geometry: { type: "Point", coordinates: [-73.92, 40.775]}, $minDistance: 10, $maxDistance: 10000}}})https://stackoverflow.com/questions/37064956
复制相似问题