我可以通过ruby驱动程序访问mongo的geoNear功能吗? [英] Can I access the geoNear functionality of mongo via the ruby driver?

查看:120
本文介绍了我可以通过ruby驱动程序访问mongo的geoNear功能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ruby驱动程序根据地理查询从mongo中检索结果。
我希望结果以各自的距离返回。
使用geoNear命令可以在shell中使用该工具:

  db.runCommand({geoNear:places,附近:[50,50],数量:10}); 

如何通过ruby API执行此操作?

解决方案

其中 db 是与您的db的连接,您可以使用 #command $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ 50,50],'num'=> 10})

这必须是 OrderedHash 在ruby 1.8中,散列在1.9中排序,所以如果使用1.9,那么你对所有的默认散列都是很好的


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?

解决方案

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

这篇关于我可以通过ruby驱动程序访问mongo的geoNear功能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆