0

I want to make look around feature in my app using geo_near i already make index on my model

  ...

  field :location, Type: Array


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

i already run

rake db:mongoid:create_indexes

here code i use in my controller

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

but i got error said :

Mongo::Error::OperationFailure (no such command: 'geoNear' (59) (on localhost:27017) (on localhost:27017)):

i using mongoid 7, ruby on rails 6.0.2, ruby 2.6.3, mongo 4.2.2

you can see full log trace here trace_log.txt

1 Answers1

0

$geoNear command (which is what Mongoid's geo_near method invokes) has been removed in MongoDB server 4.2. See https://docs.mongodb.com/manual/release-notes/4.2-compatibility/#remove-support-for-the-geonear-command.

The equivalent functionality is available in an aggregation pipeline stage - see https://docs.mongodb.com/manual/reference/operator/aggregation/geoNear/.

D. SM
  • 13,584
  • 3
  • 12
  • 21