71214

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

Question:

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?

Answer1:

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

Recommend

  • Wrong distance in geonear method with Doctrine MongoDB ODM
  • Highcharts ; x-axis scaling issue
  • Mapbox Icons/Markers “BearingSnap” or Snap to Position
  • Mongo geolocation using $near and 2d index not being accurate
  • Replacing seconds since the epoch with ordered digits in R
  • How can I create doxygen docs from boost::python docstrings?
  • One html form, several interrelated django forms - how to save?
  • How do databases sort Chinese characters?
  • TitanDB - Build a property index in descending order by timestamp
  • web shop (shopping cart) on google app engine
  • MongoDB GeoJSON “Can't extract geo keys from object, malformed geometry?” when inserting type P
  • Mongodb update() vs. findAndModify() performace
  • Stitching 2 images (OpenCV)
  • How do you keep a running instance for Google App Engine
  • my tic-tac-toe program in matlab does not work [closed]
  • jQuery - resize an elements height to match window without refreshing, on window resize
  • How can I get the full list of running processes on a Mac from a python app
  • Selenium to click on a javascript button corresponding to a text
  • pyodbc doesn't report sql server error
  • Caching attributes in superclass
  • CakePHP 2.0.4 - findBy magic methods with conditions
  • Is it possible to access block's scope in method?
  • Spark fat jar to run multiple versions on YARN
  • SignalR .NET Client Invoke throws an exception
  • Jenkins: How To Build multiple projects from a TFS repository?
  • PHP - How to update data to MySQL when click a radio button
  • How do I fake an specific browser client when using Java's Net library?
  • Is possible to count alias result on mysql
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • 'TypeError' while using NSGA2 to solve Multi-objective prob. from pyopt-sparse in OpenMDAO
  • what is the difference between the asp.net mvc application and asp.net web application
  • Upload files with Ajax and Jquery
  • Apache 2.4 - remove | delete | uninstall
  • Numpy divide by zero. Why?
  • php design question - will a Helper help here?
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • AngularJs get employee from factory
  • WPF Applying a trigger on binding failure
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Authorize attributes not working in MVC 4