开发者

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

开发者 https://www.devze.com 2023-02-16 16:40 出处:网络
I\'m retrieving results from mongo based on a geo query using the ruby driver. I\'d like the results to be returned 开发者_如何学Gowith their respective distances.

I'm retrieving results from mongo based on a geo query using the ruby driver. I'd like the results to be returned 开发者_如何学Gowith 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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号