Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Is it possible to turn an array returned by the Mongo GeoNear command (using Ruby/Rails) into a Plucky object?
- @mult = 3963 * (3.14159265 / 180 ) # Scale to miles on earth
- @results = @db.command( {'geoNear' => "places", 'near'=> @search.coordinates , 'distanceMultiplier' => @mult, 'spherical' => true})
- {"ns"=>"myapp-development.places", "near"=>"1001110101110101100100110001100010100010000010111010", "results"=>[{"dis"=>0.04356444023196527, "obj"=>{"_id"=>BSON::ObjectId('4ee6a7d210a81f05fe000001'),...}}], "stats"=>{"time"=>0, "btreelocs"=>0, "nscanned"=>1, "objectsLoaded"=>1, "avgDistance"=>0.04356444023196527, "maxDistance"=>0.0006301239824196907}, "ok"=>1.0}
- {
- "ns": "test.places",
- "near": "1100110000001111110000001111110000001111110000001111",
- "results": [
- {
- "dis": 69.29646421910687,
- "obj": {
- "_id": ObjectId("4b8bd6b93b83c574d8760280"),
- "y": [
- 1,
- 1
- ],
- "category": "Coffee"
- }
- },
- {
- "dis": 69.29646421910687,
- "obj": {
- "_id": ObjectId("4b8bd6b03b83c574d876027f"),
- "y": [
- 1,
- 1
- ]
- }
- }
- ],
- "stats": {
- "time": 0,
- "btreelocs": 1,
- "btreelocs": 1,
- "nscanned": 2,
- "nscanned": 2,
- "objectsLoaded": 2,
- "objectsLoaded": 2,
- "avgDistance": 69.29646421910687
- },
- "ok": 1
- }
- places_near['results'].each do |result|
- # do stuff with result object
- end
Add Comment
Please, Sign In to add comment