首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用$nearSphere从mongodb集合中找到数据

无法使用$nearSphere从mongodb集合中找到数据
EN

Stack Overflow用户
提问于 2016-05-06 05:32:40
回答 1查看 698关注 0票数 1

我在我的地方收藏了下面的行。

代码语言:javascript
复制
{ "_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" }

我无法执行以下查询

代码语言:javascript
复制
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 }

请告诉我是怎么回事。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-06 06:37:42

在查询对象中,缺少"loc“字段。此外,我认为您声明了minDistance和maxDistance错误,因为maxDistanace < minDistance。

我认为您想要的查询如下:

代码语言:javascript
复制
db.places.find({loc:{$nearSphere: {$geometry: { type: "Point", coordinates: [-73.92, 40.775]}, $minDistance: 10, $maxDistance: 10000}}})
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37064956

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档