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

隐身守侯 提交于 2019-12-23 19:39:31

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/5306241/can-i-access-the-geonear-functionality-of-mongo-via-the-ruby-driver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!