Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7019221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:09:17+00:00 2026-05-27T23:09:17+00:00

As a total newbie I have been trying to get the geoNear command working

  • 0

As a total newbie I have been trying to get the geoNear command working in my rails application and it appear to be working fine. The major annoyance for me is that it is returning an array with strings rather than keys which I can call on to pull out data.

Having dug around, I understand that MongoMapper uses Plucky to turn the the query resultant into a friendly object which can be handled easily but I haven’t been able to find out how to transform the result of my geoNear query into a plucky object.

My questions are:
(a) Is it possible to turn this into a plucky object and how do i do that?
(b) If it is not possible how can I most simply and systematically extract each record and each field?

here is the query in my controller

@mult = 3963 * (3.14159265 / 180 ) # Scale to miles on earth
@results = @db.command( {'geoNear' => "places", 'near'=> @search.coordinates , 'distanceMultiplier' => @mult, 'spherical' => true})

Here is the object i’m getting back (with document content removed for simplicity)

{"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}

Help is much appreciated!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:09:18+00:00Added an answer on May 27, 2026 at 11:09 pm

    Ok so lets say you store the results into a variable called places_near:

    places_near = t.command( {'geoNear' => "places", 'near'=> [50,50] , 'distanceMultiplier' => 1, 'spherical' => true})

    This command returns an hash that has a key (results) which maps to a list of results for the query. The returned document looks like this:

    {
        "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
    }
    

    To iterate over the responses just iterate as you would over any list in ruby:

    places_near['results'].each do |result|
      # do stuff with result object
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a total newbie question, so thanks in advance. I'm trying to get
So, total newbie to Git. Been reading through the guides and think I have
I am a total newbie in servers/hosting etc, although I have some experience in
Total newbie question but this is driving me mad! I'm trying this: myInt =
I'm a total newbie to SVN and haven't been able to find an answer
Be nice, I'm a total newbie to F#. I have created my first console
Total newbie to R here (so far very pleased!). I have a large array(vector?)
i'm a total newbie to java and Alfresco and i have this simple problem:
I am a total newbie with Python, I normally use Perl. I have an
Total newbie question here; I apologize in advance. Suppose I have a daemon written

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.