Guest User

Untitled

a guest
Aug 10th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. Is it possible to turn an array returned by the Mongo GeoNear command (using Ruby/Rails) into a Plucky object?
  2. @mult = 3963 * (3.14159265 / 180 ) # Scale to miles on earth
  3. @results = @db.command( {'geoNear' => "places", 'near'=> @search.coordinates , 'distanceMultiplier' => @mult, 'spherical' => true})
  4.  
  5. {"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}
  6.  
  7. {
  8. "ns": "test.places",
  9. "near": "1100110000001111110000001111110000001111110000001111",
  10. "results": [
  11. {
  12. "dis": 69.29646421910687,
  13. "obj": {
  14. "_id": ObjectId("4b8bd6b93b83c574d8760280"),
  15. "y": [
  16. 1,
  17. 1
  18. ],
  19. "category": "Coffee"
  20. }
  21. },
  22. {
  23. "dis": 69.29646421910687,
  24. "obj": {
  25. "_id": ObjectId("4b8bd6b03b83c574d876027f"),
  26. "y": [
  27. 1,
  28. 1
  29. ]
  30. }
  31. }
  32. ],
  33. "stats": {
  34. "time": 0,
  35. "btreelocs": 1,
  36. "btreelocs": 1,
  37. "nscanned": 2,
  38. "nscanned": 2,
  39. "objectsLoaded": 2,
  40. "objectsLoaded": 2,
  41. "avgDistance": 69.29646421910687
  42. },
  43. "ok": 1
  44. }
  45.  
  46. places_near['results'].each do |result|
  47. # do stuff with result object
  48. end
Add Comment
Please, Sign In to add comment