Mongo Server error (MongoCommandException): Command failed with error 2 (BadValue): 'geo near accepts just one argument when querying for a GeoJSON point. Extra field found: $minDistance: 1000.0'

Rashmi
Rashmi
Member
820 Points
17 Posts

I'm using geoNear stage for geoSpacial query in mongodb but in some cases getting following error:

Mongo Server error (MongoCommandException): Command failed with error 2 (BadValue): 'geo near accepts just one argument when querying for a GeoJSON point. Extra field found: $minDistance: 1000.0' 

I'm trying following query:

db.getCollection("location").aggregate([
{
$geoNear: {
    "near": {
        "type": "Point",
        "coordinates": [
            13.5178498,
            144.8120691
        ]
    },
    "minDistance": 1000,
    "maxDistance": 5000,
    "distanceField": "distance"
      }
}]);

 

Views: 689
Total Answered: 1
Total Marked As Answer: 1
Posted On: 05-Apr-2023 05:54

Share:   fb twitter linkedin
Answers
Rashmi
Rashmi
Member
820 Points
17 Posts
         

Resolved issue after long analysis. It's resolved by reversing lat/long to long/lat as:

db.getCollection("location").aggregate([
{
$geoNear: {
    "near": {
        "type": "Point",
        "coordinates": [
            144.8120691,
            13.5178498
        ]
    },
    "minDistance": 1000,
    "maxDistance": 5000,
    "distanceField": "distance"
      }
}]);
Posted On: 07-Apr-2023 00:20
Thanks for sharing solution.
 - Brian  07-Apr-2023 00:21
 Log In to Chat