Last active
December 27, 2015 12:39
-
-
Save jystewart/7327162 to your computer and use it in GitHub Desktop.
Quick example of how to do a geo query with the moped library and convert the output to JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'moped' | |
require 'yajl' | |
session = Moped::Session.new([ "127.0.0.1:27017" ]) | |
session.use "imminence_development" | |
query = session.command({ | |
geoNear: "places", | |
near: [ -2.16933984212885, 52.27229461855149 ], | |
spherical: false, | |
query: { service_slug: "register-offices", data_set_version: 2 }, | |
num: 5 | |
}) | |
output = query['results'].collect { |row| row['obj']['distance'] = row['dis']; row['obj'] } | |
# Use YAJL as it's said to be much faster than the core JSON lib | |
Yajl::Encoder.encode(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment