-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
-
Storage Execution
-
Minor Change
-
v5.0
-
Execution Team 2021-11-01, Execution Team 2021-11-15, Sharding EMEA 2021-12-13, Sharding EMEA 2021-12-27, Sharding EMEA 2022-01-10, Execution Team 2023-02-20
-
155
Previously, mongod would return an error if you attempted to create a collection or view that already existed. However, mongos would report success if the collection/view already existed with the same exact options you were attempting to create it with. The mongod behavior now matches the mongos behavior, i.e. on both mongod and mongos the create command is idempotent and will report success if an identical collection/view already exists, meaning it is safe to re-run the command even if it may have succeeded previously.
Original ticket description:
Related to SERVER-33276 and PYTHON-1936. Starting in MongoDB 4.0, the create command does not return an error when the collection already exists on sharded clusters:
>>> client.server_info()['version'] '4.2.3' >>> client.is_mongos True >>> client.test.command('create', 'test', check=False) {'ok': 1.0} >>> client.test.command('create', 'test', check=False) {'ok': 1.0}
On replica sets and standalones the second create fails with error code 48:
>>> client.server_info()['version'] '4.2.3' >>> client.is_mongos False >>> client.test.command('create', 'test', check=False) {'ok': 1.0} >>> client.test.command('create', 'test', check=False) {'ok': 0.0, 'errmsg': "a collection 'test.test' already exists", 'code': 48, 'codeName': 'NamespaceExists'}
We should make mongod have the same behavior as mongos for consistency across deployments.
Another benefit of this change is that it would allow drivers to retry the create command like mongos does.
- causes
-
SERVER-74330 Prevent nullptr access in checkCollectionOptions uassert
- Closed
- is depended on by
-
SERVER-73967 Update handling of create command in shouldRetryWithNetworkErrorOverride
- Closed
-
PYTHON-1936 Remove listCollections check from Database.create_collection
- Closed
-
COMPASS-6526 Investigate changes in SERVER-60064: Create on an existing collection on mongod should have the same behavior as mongos
- Closed
- is duplicated by
-
SERVER-60933 Make the sharded cluster's 'create' command behave the same as replica set
- Closed
- is related to
-
SERVER-76547 Create command on a time-series collection is not idempotent
- Closed
-
SERVER-74062 Remove test checks for DB version >= 7.0 in tests relying on idempotency of create command
- Closed
-
SERVER-94982 Audit idempotency of all DDL operations
- Needs Scheduling
-
SERVER-82074 Refactor collection creation idempotency to use single collection acquisition
- Backlog
- related to
-
SERVER-90152 dropIndex() should be idempotent
- Blocked
-
SERVER-32550 Drop of a non-existing collection on mongod should have the same behavior as mongos
- Closed
-
SERVER-73934 Remove commandWorkedOrFailedWithCode(NamespaceNotFound) from drop_collection.js when 7.0 is last stable release in multi version testing
- Closed
-
SERVER-33276 Creation of already existing collection on a sharded cluster should be an error
- Closed
-
SERVER-43894 Make dropping a nonexistent collection a noop
- Closed