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

Make create command idempotent on mongod

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.0.0-rc0
    • 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.

        1. SERVER-60064 Sharded.txt
          5 kB
          Antonio Fuschetto
        2. SERVER-60064 Standalone.txt
          2 kB
          Antonio Fuschetto

            Votes:
            0 Vote for this issue
            Watchers:
            27 Start watching this issue

              Created:
              Updated:
              Resolved: