【问题标题】:no such command: 'geoNear', when using geo_near with mongoid没有这样的命令:'geoNear',当将 geo_near 与 mongoid 一起使用时
【发布时间】:2020-01-05 01:51:02
【问题描述】:

我想使用 geo_near 在我的应用中创建环视功能 我已经在我的模型上建立了索引

  ...

  field :location, Type: Array


  index({ location: "2d" })
  self.create_indexes

我已经跑了

rake db:mongoid:create_indexes

这是我在控制器中使用的代码

  @merchants = Merchant.geo_near([coordinate.first.to_f, coordinate.last.to_f]).max_distance(50)

但我得到错误说:

Mongo::Error::OperationFailure(没有这样的命令:'geoNear' (59)(在 localhost:27017 上)(在 localhost:27017 上)):

我使用 mongoid 7、ruby on rails 6.0.2、ruby 2.6.3、mongo 4.2.2

你可以在这里看到完整的日志跟踪trace_log.txt

【问题讨论】:

    标签: ruby-on-rails mongoid geonear


    【解决方案1】:

    $geoNear 命令(这是 Mongoid 的 geo_near 方法调用的)已在 MongoDB 服务器 4.2 中删除。见https://docs.mongodb.com/manual/release-notes/4.2-compatibility/#remove-support-for-the-geonear-command

    聚合管道阶段提供等效功能 - 请参阅 https://docs.mongodb.com/manual/reference/operator/aggregation/geoNear/

    【讨论】:

      猜你喜欢
      • 2012-10-28
      • 1970-01-01
      • 2017-08-06
      • 2020-02-07
      • 1970-01-01
      • 2012-07-14
      • 2013-12-05
      • 2020-06-27
      相关资源
      最近更新 更多