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

collStats command does not return an error when the collection does not exist on sharded clusters

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 4.2.9, 4.4.1
    • Component/s: None
    • Catalog and Routing
    • ALL
    • CAR Team 2024-01-22
    • 1

      On MongoDB 4.2/4.4 sharded clusters, the collStats command returns an error on a non-existent database but not on a non-existent collection within an existing database:

      >>> client.admin.command('buildInfo')['version']
      '4.2.9'
      >>> client.core.test.insert_one({})
      <pymongo.results.InsertOneResult object at 0x7f886b59f680>
      >>> client.core.list_collection_names()
      ['test']
      >>> client.idontexist.command("collstats", 'idontexist', check=False)
      {'ok': 0.0, 'errmsg': 'database idontexist not found', 'code': 26, 'codeName': 'NamespaceNotFound', 'operationTime': Timestamp(1601349800, 22), '$clusterTime': {'clusterTime': Timestamp(1601349800, 22), 'signature': {'hash': b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'keyId': 0}}}
      >>> client.core.command("collstats", 'idontexist')
      {'sharded': False, 'primary': 'demo-set-0', 'indexDetails': {}, 'ns': 'core.idontexist', 'count': 0, 'size': 0, 'storageSize': 0, 'totalIndexSize': 0, 'indexSizes': {}, 'avgObjSize': 0.0, 'maxSize': 0, 'nindexes': 0, 'nchunks': 1, 'shards': {'demo-set-0': {'ns': 'core.idontexist', 'size': 0, 'count': 0, 'storageSize': 0, 'nindexes': 0, 'totalIndexSize': 0, 'indexDetails': {}, 'indexSizes': {}, 'scaleFactor': 1, 'ok': 1.0, '$gleStats': {'lastOpTime': {'ts': Timestamp(1601349779, 1), 't': 1}, 'electionId': ObjectId('7fffffff0000000000000001')}, 'lastCommittedOpTime': Timestamp(1601349809, 15), '$configServerState': {'opTime': {'ts': Timestamp(1601349809, 17), 't': 1}}, '$clusterTime': {'clusterTime': Timestamp(1601349809, 22), 'signature': {'hash': b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'keyId': 0}}, 'operationTime': Timestamp(1601349809, 15)}}, 'ok': 1.0, 'operationTime': Timestamp(1601349809, 15), '$clusterTime': {'clusterTime': Timestamp(1601349809, 22), 'signature': {'hash': b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'keyId': 0}}}
      

      This behavior is inconsistent. On 4.0 and earlier both scenarios result in an error:

      >>> client.admin.command('buildInfo')['version']
      '4.0.20'
      >>> client.idontexist.command("collstats", 'idontexist', check=False)
      {'ok': 0.0, 'errmsg': 'database idontexist not found', 'code': 26, 'codeName': 'NamespaceNotFound', 'operationTime': Timestamp(1601350251, 2), '$clusterTime': {'clusterTime': Timestamp(1601350251, 2), 'signature': {'hash': b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'keyId': 0}}}
      >>> client.core.command("collstats", 'idontexist', check=False)
      {'ok': 0.0, 'errmsg': 'Collection [core.idontexist] not found.', 'code': 8, 'codeName': 'UnknownError', 'operationTime': Timestamp(1601350188, 1), '$clusterTime': {'clusterTime': Timestamp(1601350189, 1), 'signature': {'hash': b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'keyId': 0}}}
      

      Note that there seems to be another bug here. Notice that in 4.0.20 the second error code is UnknownError when it surely should be NamespaceNotFound. This is related to SERVER-50070 but not quite the same.

            Assignee:
            silvia.surroca@mongodb.com Silvia Surroca
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: