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

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

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major - P3 Major - P3
    • None
    • 4.0.4
    • 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);

    Description

      $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

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: