0
votes

I am firing the following query, the latitude and longitude chosen here is for a place in New York City -

db.acollection.find({"afield.location": {$near:[40.744010,-73.989334],$maxDistance :3.4}})

and I am able to get the following location in my results -

 "afield" : [ 
        {
            "country" : "United States",
            "countryCode" : "US",
            "location" : {
                "lat" : 42.3584308,
                "long" : -71.0597732
            },
            "name" : "Boston",
            "state" : "Massachusetts"
        }
    ]

Why do I need to specify at least 3.4 as maxDistance? The radius of earth is 3,959 miles. The distance between New York(U.S.A. - New York) and Boston(U.S.A. - Massachusetts) using the link below is 191 miles.
http://www.timeanddate.com/worldclock/distanceresult.html?p1=179&p2=43

I need to specify maxDistance in radians - http://docs.mongodb.org/manual/reference/operator/query/near/

Why does the query not work if I use maxDistance as .05 that is 191/3959?

Why do I need to use a much greater value?

1

1 Answers

0
votes

There are degrees, not radians. Mongo docs:

The measuring units for the maximum distance are determined by the coordinate system in use.