[SERVER-79226] Accuracy differences in geoNear aggregation between mongod 5.0 and 6.0 Created: 22/Jul/23  Updated: 02/Nov/23  Resolved: 02/Nov/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 6.0.8
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: 罗震宇 N/A Assignee: Backlog - Triage Team
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-74983 Divergence in sin/cos functions acros... Closed
Assigned Teams:
Server Triage
Operating System: ALL
Participants:

 Description   

The results of geoNear example are different on mongo 5.0 and 6.0.

9.539931676365992 against 9.539931674131209

https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/

Therefore, some unit test failed.

https://github.com/mongodb/mongo-java-driver/blob/master/driver-core/src/test/functional/com/mongodb/client/model/AggregatesTest.java#L237

 

Result of mongo 5.0.17:

[{"_id": 2, "name": "Sara D. Roosevelt Park", "category": "Parks", "location":

{"type": "Point", "coordinates": [-73.9928, 40.7193]}

, "dist": {"calculated": 9.539931676365992, "location":

{"type": "Point", "coordinates": [-73.9928, 40.7193]}

}}]

 

Result of mongo 6.0.8:

[{"_id": 2, "name": "Sara D. Roosevelt Park", "location":

{"type": "Point", "coordinates": [-73.9928, 40.7193]}

, "category": "Parks", "dist": {"calculated": 9.539931674131209, "location":

{"type": "Point", "coordinates": [-73.9928, 40.7193]}

}}]



 Comments   
Comment by Edwin Zhou [ 02/Nov/23 ]

Hi lzy@luozy.cn,

Thank you for your report and your patience on this issue. I also appreciate the details that you've provided. After further investigation, it appears this ticket duplicates SERVER-74983, where a difference in platforms may introduce a difference in trig implementations and results.

JAVA-5097 decreases the number of significant figures to 4 to prevent the test failure you pointed to in your description.

I've closed this ticket as a duplicate to SERVER-74983.

Kind regards,
Edwin

Comment by 罗震宇 N/A [ 25/Jul/23 ]

yuan.fang@mongodb.com Just use the example in MongoDB document.

https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/#-geonear--aggregation-

Reproduce

db.places.insertMany( [
   

{       name: "Central Park",       location: \{ type: "Point", coordinates: [ -73.97, 40.77 ] }

,
      category: "Parks"
   },
   

{       name: "Sara D. Roosevelt Park",       location: \{ type: "Point", coordinates: [ -73.9928, 40.7193 ] }

,
      category: "Parks"
   },
   

{       name: "Polo Grounds",       location: \{ type: "Point", coordinates: [ -73.9375, 40.8303 ] }

,
      category: "Stadiums"
   }
] )

db.places.createIndex( { location: "2dsphere" } )

db.places.aggregate([
   {
     $geoNear:

{         near: \{ type: "Point", coordinates: [ -73.99279 , 40.719296 ] }

,
        distanceField: "dist.calculated",
        maxDistance: 2,
        query: { category: "Parks" },
        includeLocs: "dist.location",
        spherical: true
     }
   }
])

MongoDB 5.0.17

[

  {

    _id: ObjectId("64bf846fb1c9448e80a6cece"),

    name: 'Sara D. Roosevelt Park',

    location:

{ type: 'Point', coordinates: [ -73.9928, 40.7193 ] }

,

    category: 'Parks',

    dist: {

      calculated: 0.9539931676365992,

      location:

{ type: 'Point', coordinates: [ -73.9928, 40.7193 ] }

    }

  }

]

MongoDB 6.0.8

[

  {

    _id: ObjectId("64bf838e534317ffa0f4f161"),

    name: 'Sara D. Roosevelt Park',

    location:

{ type: 'Point', coordinates: [ -73.9928, 40.7193 ] }

,

    category: 'Parks',

    dist: {

      calculated: 0.9539931674131209,

      location:

{ type: 'Point', coordinates: [ -73.9928, 40.7193 ] }

    }

  }

]

Comment by Yuan Fang [ 24/Jul/23 ]

Hi lzy@luozy.cn ,

Thank you for your report. I understand that you have noticed inconsistent results with the $geoNear aggregation in versions v5.0.x and v6.0.8.  Could you provide more information to help us in reproducing the issue?  Specifically, we would appreciate it if you could provide the following:

  • The aggregation pipeline that you used.
  • An example of datasets on which you applied the mentioned pipeline.

Regards,
Yuan

 

Generated at Thu Feb 08 06:40:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.