我想使用geo_near在我的应用程序中制作环顾四周的功能 我已经在我的模型上做了索引
...
field :location, Type: Array
index({ location: "2d" })
self.create_indexes
我已经跑了
耙子数据库:蒙古:create_indexes
这是我在控制器中使用的代码
@merchants = Merchant.geo_near([coordinate.first.to_f, coordinate.last.to_f]).max_distance(50)
但我得到错误说:
Mongo::Error::OperationFailure (没有这样的命令: 'geoNear' (59( (在本地主机上:27017( (在本地主机上:27017上((:
我使用 Mongoid 7、Ruby on Rails 6.0.2、Ruby 2.6.3、MONGO 4.2.2
您可以在此处查看完整的日志跟踪trace_log.txt
$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/。