com.mongodb.MongoCommandException: Command failed with error 48 (NamespaceExists) MongoDB报错
2021/7/20 19:40:15
本文主要是介绍com.mongodb.MongoCommandException: Command failed with error 48 (NamespaceExists) MongoDB报错,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
- 报错
com.mongodb.MongoCommandException: Command failed with error 48 (NamespaceExists): 'a collection 'mapMongoDB.macCode01' already exists' on server localhost:27017. The full response is { "ok" : 0.0, "errmsg" : "a collection ' **mapMongoDB.macCode01** ' already exists", "code" : 48, "codeName" : "NamespaceExists" } at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:179) at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:293) at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:255) at com.mongodb.internal.connection.UsageTrackingInternalConnection.sendAndReceive(UsageTrackingInternalConnection.java:99) at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.sendAndReceive(DefaultConnectionPool.java:444) at com.mongodb.internal.connection.CommandProtocolImpl.execute(CommandProtocolImpl.java:72) at com.mongodb.internal.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:200) at com.mongodb.internal.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:269) at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:131) at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:123) at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:242) at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:233) at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:170) at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:163) at com.mongodb.operation.CreateCollectionOperation$1.call(CreateCollectionOperation.java:381) at com.mongodb.operation.CreateCollectionOperation$1.call(CreateCollectionOperation.java:377) at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:453) at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:415) at com.mongodb.operation.CreateCollectionOperation.execute(CreateCollectionOperation.java:377) at com.mongodb.operation.CreateCollectionOperation.execute(CreateCollectionOperation.java:54) at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:193) at com.mongodb.client.internal.MongoDatabaseImpl.executeCreateCollection(MongoDatabaseImpl.java:300) at com.mongodb.client.internal.MongoDatabaseImpl.createCollection(MongoDatabaseImpl.java:257) at com.mongodb.client.internal.MongoDatabaseImpl.createCollection(MongoDatabaseImpl.java:252) at com.example.demo.Demo.mongoDBRepository.mongoDBRepository.main(mongoDBRepository.java:24)
- 原因
- 当前库中的集合已经存在了,再次创建会抛出异常
- 解决方案一
- 删除存在的集合:** db.macCode01.drop(); **
- 解决方案二
- 创建新的集合:** db.createCollection("collName", {size: 20, capped: 5, max: 100});//创建成功会显示{"ok":1} **
这篇关于com.mongodb.MongoCommandException: Command failed with error 48 (NamespaceExists) MongoDB报错的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-20go-zero 框架的 RPC 服务 启动start和停止 底层是怎么实现的?-icode9专业技术文章分享
- 2024-12-19Go-Zero 框架的 RPC 服务启动和停止的基本机制和过程是怎么实现的?-icode9专业技术文章分享
- 2024-12-18怎么在golang中使用gRPC测试mock数据?-icode9专业技术文章分享
- 2024-12-15掌握PageRank算法核心!你离Google优化高手只差一步!
- 2024-12-15GORM 中的标签 gorm:"index"是什么?-icode9专业技术文章分享
- 2024-12-11怎么在 Go 语言中获取 Open vSwitch (OVS) 的桥接信息(Bridge)?-icode9专业技术文章分享
- 2024-12-11怎么用Go 语言的库来与 Open vSwitch 进行交互?-icode9专业技术文章分享
- 2024-12-11怎么在 go-zero 项目中发送阿里云短信?-icode9专业技术文章分享
- 2024-12-11怎么使用阿里云 Go SDK (alibaba-cloud-sdk-go) 发送短信?-icode9专业技术文章分享
- 2024-12-10搭建个人博客网站之一、使用hugo创建个人博客网站