48 NamespaceExists: Namespace (collection) already exists
MongoDBWhat does it mean?
The collection (namespace) you are trying to create already exists. MongoDB reports that it is present, so there is no need to create a new collection with the same name and options.
Why does it happen?
Trying to re-create an existing collection with createCollection (possibly with different options); schema/setup scripts run more than once; or attempting to redefine an existing name as a capped collection or with special options.
How to fix it
Usually safe to ignore; it means the collection already exists. Make your setup scripts idempotent: check existence before creating (db.getCollectionNames().includes('name')). To change the options you must drop and re-create the collection (back up the data first): db.my_collection.drop() then createCollection.
More from this engine
- 31 RoleNotFoundRole not found
- 263 OperationNotSupportedInTransactionOperation not supported inside a multi-document transaction
- 20 IllegalOperationIllegal operation
- 11601 InterruptedOperation was interrupted
- 85 IndexOptionsConflictIndex already exists with different options / different name
- 67 CannotCreateIndexCannot create index
- 27 IndexNotFoundIndex not found