Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-38236

$geoNear (aggregation) when $maxDistance = 0, return all locations

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 4.0.4
    • Component/s: Aggregation Framework
    • None
    • ALL
    • Hide
      db.createCollection("places");
      db.places.createIndex({ location : "2dsphere" } );
      db.places.insert([
       {"name" : "place 1",
       "location" : {
       "type" : "Point",
       "coordinates" : [ -50, 50 ]
       }}, 
       {"name" : "place 2",
       "location" : {
       "type" : "Point",
       "coordinates" : [ -60, 60 ]
       }}
      ]);
      
      var count = db.places.aggregate([
       {
       $geoNear: {
       near: \{ type: "Point", coordinates: [ -50 , 50 ] },
       maxDistance: 0,
       spherical: true,
       distanceField: "dist.calculated",
       includeLocs: "dist.location",
       }
       }
      ]).toArray().length
      
      print(count);
      
      Show
      db.createCollection( "places" ); db.places.createIndex({ location : "2dsphere" } ); db.places.insert([ { "name" : "place 1" , "location" : { "type" : "Point" , "coordinates" : [ -50, 50 ] }}, { "name" : "place 2" , "location" : { "type" : "Point" , "coordinates" : [ -60, 60 ] }} ]); var count = db.places.aggregate([ { $geoNear: { near: \{ type: "Point" , coordinates: [ -50 , 50 ] }, maxDistance: 0, spherical: true , distanceField: "dist.calculated" , includeLocs: "dist.location" , } } ]).toArray().length print(count);

      $geoNear with $maxDistance = 0, it doesn't return the only one matching location.

      It returns all locations. The behaviour is the same as $maxDistance=Double.max

            Assignee:
            daniel.hatcher@mongodb.com Danny Hatcher (Inactive)
            Reporter:
            lindenquan linden quan
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: