没有此类命令:'geoNear',当将geo_near与蒙皮一起使用时

问题描述 投票:0回答:1

我想使用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,轨上的红宝石6.0.2,红宝石2.6.3,蒙戈4.2.2

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

ruby-on-rails mongoid geonear
1个回答
0
投票

$ 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/

© www.soinside.com 2019 - 2024. All rights reserved.