48 NamespaceExists: Namespace (collection) already exists(命名空间(集合)已存在)
MongoDB含义
要创建的集合(命名空间)已存在。MongoDB 报告它已存在,因此无需再用相同名称和选项创建新集合。
原因
试图用 createCollection 重新创建已存在的集合(可能带有不同选项);架构/初始化脚本运行了多次;或试图将已存在的名称重新定义为 capped 集合或带特殊选项的集合。
解决方法
通常可以安全忽略;它表示集合已存在。使初始化脚本幂等:创建前检查是否存在(db.getCollectionNames().includes('name'))。要更改选项,必须删除并重新创建集合(先备份数据):db.my_collection.drop() 然后 createCollection。
同一数据库的其他条目
- 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(未找到索引)