[SERVER-50074] geoNear returns different stats in sharded cluster vs other topologies Created: 03/Aug/20  Updated: 06/Dec/22  Resolved: 18/Aug/20

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

Type: Bug Priority: Minor - P4
Reporter: Oleg Pudeyev (Inactive) Assignee: Backlog - Query Team (Inactive)
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to MONGOID-4915 Add more test configurations, fix sha... Closed
Assigned Teams:
Query
Operating System: ALL
Participants:

 Description   

This seems to only affect 4.0. 3.6 does not appear to be affected, I did not test earlier versions, in 4.2 there is no geoNear command.

I use the following code to send a geoNear query that returns no results:

db.foo.deleteMany({})
db.foo.insert({a:1})
db.foo.createIndex({point:"2dsphere"})
a=db.runCommand({geoNear:'foo',near:{type:'Point',coordinates:[1,1]},spherical:true})
print(JSON.stringify(a))

On a 4.0 replica set I get:

serene% mongo --port 14020 test.js
MongoDB shell version v4.4.0
connecting to: mongodb://127.0.0.1:14020/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("acb72480-9081-4750-b085-2900c9402ef1") }
MongoDB server version: 4.0.16
WARNING: shell and server versions do not match
{"results":[],"stats":{"nscanned":0,"objectsLoaded":0,"maxDistance":0,"time":843},"ok":1,"operationTime":{"$timestamp":{"t":1596417427,"i":4}},"$clusterTime":{"clusterTime":{"$timestamp":{"t":1596417427,"i":4}},"signature":{"hash":{"$binary":"AAAAAAAAAAAAAAAAAAAAAAAAAAA=","$type":"00"},"keyId":{"$numberLong":"0"}}}}

Note avgDistance field is missing from stats.

On a 4.0 sharded cluster I get:

serene% mongo --port 14040 test.js
MongoDB shell version v4.4.0
connecting to: mongodb://127.0.0.1:14040/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("a8513a92-741e-4148-8cc4-d3192717f395") }
MongoDB server version: 4.0.16
WARNING: shell and server versions do not match
{"ns":"test.foo","near":"","results":[],"stats":{"time":218,"btreelocs":0,"nscanned":0,"objectsLoaded":0,"avgDistance":0,"maxDistance":0,"shards":["shard02"]},"ok":1,"operationTime":{"$timestamp":{"t":1596417437,"i":2}},"$clusterTime":{"clusterTime":{"$timestamp":{"t":1596417437,"i":2}},"signature":{"hash":{"$binary":"AAAAAAAAAAAAAAAAAAAAAAAAAAA=","$type":"00"},"keyId":{"$numberLong":"0"}}}}

Note avgDistance is present in stats, along with a few other fields not present in the RS response.

In 3.6 sharded cluster these fields aren't present either:

serene% mongo --port 13650 test.js 
MongoDB shell version v4.4.0
connecting to: mongodb://127.0.0.1:13650/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("7f5da47b-dbd5-4c87-abb5-61a180467459") }
MongoDB server version: 3.6.18
WARNING: shell and server versions do not match
{"results":[],"stats":{"nscanned":0,"objectsLoaded":0,"maxDistance":0,"time":207},"ok":1,"operationTime":{"$timestamp":{"t":1596417614,"i":3}},"$clusterTime":{"clusterTime":{"$timestamp":{"t":1596417614,"i":3}},"signature":{"hash":{"$binary":"AAAAAAAAAAAAAAAAAAAAAAAAAAA=","$type":"00"},"keyId":{"$numberLong":"0"}}}}

Mongoid provides helpers that extract e.g. avgDistance from this response, and these helpers return different data based on the topology in 4.0. Other drivers may have similar helpers.

Test code: https://github.com/p-mongo/tests/blob/master/server-geo-near/test.js

The above tests were made on 4.0.16 but I tested 4.0.19 also:

root@f5643f0ed1e4:/app# mongo test.js
MongoDB shell version v4.0.19
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("b0bfb134-13c5-418c-be02-177497214094") }
MongoDB server version: 4.0.19
{"ns":"test.foo","near":"","results":[],"stats":{"time":14655,"btreelocs":0,"nscanned":0,"objectsLoaded":0,"avgDistance":0,"maxDistance":0,"shards":["shard01"]},"ok":1,"operationTime":{"$timestamp":{"t":1596418300,"i":14}},"$clusterTime":{"clusterTime":{"$timestamp":{"t":1596418300,"i":14}},"signature":{"hash":{"$binary":"AAAAAAAAAAAAAAAAAAAAAAAAAAA=","$type":"00"},"keyId":{"$numberLong":"0"}}}}



 Comments   
Comment by Craig Homa [ 18/Aug/20 ]

Closing as wont fix because the geoNear command has been removed and is not in the last 2 stable release branches.

Comment by Githook User [ 03/Aug/20 ]

Author:

{'name': 'Oleg Pudeyev', 'email': '39304720+p-mongo@users.noreply.github.com', 'username': 'p-mongo'}

Message: MONGOID-4915 Add more test configurations, fix sharding tasks on pre-4.2 servers (#4805)

  • fix sharded test
  • fix sharding tasks on 3.6/4.0
  • test 2.6 with sharded clusters
  • account for 2.6 servers not allowing enabling sharding multiple times
  • test all server versions
  • 3.2 assigns code 23 to already enabled error

Co-authored-by: Oleg Pudeyev <oleg@bsdpower.com>
Branch: 7.1-stable
https://github.com/mongodb/mongoid/commit/21b618805da852a4dd32cdcc9b7cf6d05e3e2f0f

Comment by Githook User [ 03/Aug/20 ]

Author:

{'name': 'Oleg Pudeyev', 'email': '39304720+p-mongo@users.noreply.github.com', 'username': 'p-mongo'}

Message: MONGOID-4915 Add more test configurations, fix sharding tasks on pre-4.2 servers (#4805)

  • fix sharded test
  • fix sharding tasks on 3.6/4.0
  • test 2.6 with sharded clusters
  • account for 2.6 servers not allowing enabling sharding multiple times
  • test all server versions
  • 3.2 assigns code 23 to already enabled error

Co-authored-by: Oleg Pudeyev <oleg@bsdpower.com>
Branch: master
https://github.com/mongodb/mongoid/commit/9dee93c01d10269535fc25031b52077630152eab

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