-
Type: Bug
-
Resolution: Duplicate
-
Priority: 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.
- duplicates
-
SERVER-29678 collStats should return ok:1 and all fields when the namespace does not exist
- Closed
- related to
-
SERVER-50070 collStats does not return error code when asked to operate on a non-existent collection in an existing database
- Backlog
-
SERVER-29678 collStats should return ok:1 and all fields when the namespace does not exist
- Closed