[SERVER-38236] $geoNear (aggregation) when $maxDistance = 0, return all locations Created: 24/Nov/18  Updated: 26/Nov/18  Resolved: 26/Nov/18

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: 4.0.4
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: linden quan Assignee: Danny Hatcher (Inactive)
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-35043 Remove geoNear command Closed
duplicates SERVER-22949 Remove default limit from $geoNear ag... Closed
Operating System: ALL
Steps To Reproduce:

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);

Participants:

 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



 Comments   
Comment by Danny Hatcher (Inactive) [ 26/Nov/18 ]

Hello,

Thank you for contacting us. I've confirmed that your steps to reproduce do show two results when specifying a maxDistance of 0. However, in our work in SERVER-35043 and SERVER-22949 we have changed the code to only specify 1 result when a maxDistance of 0 is set. You can test this yourself as of the development release 4.1.1. As the functionality will be publicly changed in 4.2.0, I will close this ticket as a duplicate of those aforementioned tickets.

Thank you,

Danny

Comment by linden quan [ 26/Nov/18 ]

please remove back-slash in code in Steps To Reproduce section

Comment by linden quan [ 24/Nov/18 ]

I tested on Ubuntu 18

$nearSphere returns only one result which is correct behaviour.

db.places.find({
    "location": {
        "$nearSphere": {
            $maxDistance: 0,
            "$geometry": {
                "type": "Point",
                "coordinates": [-50, 50]
            }
        }
    }
}).count(); // returns 1

Generated at Thu Feb 08 04:48:21 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.