Guy Argo
Guy Argo

Reputation: 407

Can I access the geoNear functionality of mongo via the ruby driver?

I'm retrieving results from mongo based on a geo query using the ruby driver. I'd like the results to be returned with their respective distances. That facility is available at the shell using geoNear command:

db.runCommand( { geoNear : "places", near : [50,50], num : 10 } );

How do I do this via the ruby API?

Upvotes: 3

Views: 821

Answers (1)

Michael Papile
Michael Papile

Reputation: 6856

where db is the connection to your db you can use #command :

  db.command({'geoNear' => "places", 'near'=>[50,50], 'num' => 10})

This has to be an OrderedHash in ruby 1.8, hashes are ordered in 1.9 so you are all good with default hash if using 1.9

Upvotes: 3

Related Questions