【问题标题】:Meteor - MongoDB deployed query 2dsphereMeteor - MongoDB 部署查询 2dsphere
【发布时间】:2014-12-18 08:20:36
【问题描述】:

使用meteorjs,当我使用本地主机时,我可以让它工作。但是当我部署到流星时,我在日志中收到以下错误。

INFO 队列任务中的异常:MongoError:找不到任何特殊索引:2d(需要索引),2dsphere(需要索引),用于:{ location: { $near: { $geometry: { type: "Point" , 坐标: [ -80 , 40 ] }, $minDistance: 0, $maxDistance: 500 } } }

有人知道为什么吗?我已经确保该位置实际上是 2dsphere 类型。

【问题讨论】:

  • 你是如何创建索引的?你在使用_ensureIndex 还是你是怎么做到的?
  • 事实证明,$geoWithin 没有使用 $near,而是起作用了。

标签: mongodb meteor


【解决方案1】:

您需要先设置地理空间索引。您可以使用 _ensureIndex 方法在服务器部分的 javascript 代码中执行此操作。

        MyCollection._ensureIndex({ "location": "2dsphere"});

在 MongoDB 文档中查看更多信息:http://docs.mongodb.org/manual/tutorial/build-a-2dsphere-index/

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-20
  • 2021-07-14
  • 2021-04-17
相关资源
最近更新 更多