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

geoNear returns different stats in sharded cluster vs other topologies

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 4.0.19
    • Component/s: Geo
    • None
    • Query
    • ALL

      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"}}}}
      

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: