MongoDB(Wired tiger):向上插入错误,并使用;重复密钥错误";-多线程
在MongoDB(Wired tiger):向上插入错误,并使用;重复密钥错误";-多线程,mongodb,mongodb-query,mongodb-java,Mongodb,Mongodb Query,Mongodb Java,在mongodb中执行upsert时,我在应用程序中遇到了以下错误: 例外情况 com.mongodb.MongoBulkWriteException: Bulk write operation error on server Write errors: [BulkWriteError{index=0, code=11000, message='E11000 duplicate key error collection: index: _id_ dup key: { : at com.mong
mongodb
中执行upsert
时,我在应用程序中遇到了以下错误:
例外情况
com.mongodb.MongoBulkWriteException: Bulk write operation error on server
Write errors: [BulkWriteError{index=0, code=11000, message='E11000 duplicate key error collection: index: _id_ dup key: { :
at com.mongodb.connection.BulkWriteBatchCombiner.getError(BulkWriteBatchCombiner.java:176) ~[mongo-java-driver-3.0.2.jar:na]
at com.mongodb.connection.BulkWriteBatchCombiner.throwOnError(BulkWriteBatchCombiner.java:205) ~[mongo-java-driver-3.0.2.jar:na]
at com.mongodb.connection.BulkWriteBatchCombiner.getResult(BulkWriteBatchCombiner.java:146) ~[mongo-java-driver-3.0.2.jar:na]
at com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:159) ~[mongo-java-driver-3.0.2.jar:na]
at com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:141) ~[mongo-java-driver-3.0.2.jar:na]
at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:186) ~[mongo-java-driver-3.0.2.jar:na]
at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:177) ~[mongo-java-driver-3.0.2.jar:na]
Ref
搜索后,我们发现JIRA中有两个未决问题:
注意:我们的应用程序是多线程的。两个不同的线程正在执行批量升级
问题
com.mongodb.MongoBulkWriteException: Bulk write operation error on server
Write errors: [BulkWriteError{index=0, code=11000, message='E11000 duplicate key error collection: index: _id_ dup key: { :
at com.mongodb.connection.BulkWriteBatchCombiner.getError(BulkWriteBatchCombiner.java:176) ~[mongo-java-driver-3.0.2.jar:na]
at com.mongodb.connection.BulkWriteBatchCombiner.throwOnError(BulkWriteBatchCombiner.java:205) ~[mongo-java-driver-3.0.2.jar:na]
at com.mongodb.connection.BulkWriteBatchCombiner.getResult(BulkWriteBatchCombiner.java:146) ~[mongo-java-driver-3.0.2.jar:na]
at com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:159) ~[mongo-java-driver-3.0.2.jar:na]
at com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:141) ~[mongo-java-driver-3.0.2.jar:na]
at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:186) ~[mongo-java-driver-3.0.2.jar:na]
at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:177) ~[mongo-java-driver-3.0.2.jar:na]
为了避免失败并用正确的值更新文档,在应用程序端用Java编写代码的替代方法是什么?。由于这似乎只适用于WT(),因此一种简单的方法是更改存储引擎,在由副本集支持的副本集/分片集群中,应该可以不停机。根据Java方面:您必须在要写入的对象上进行同步,这对于一个bug来说是一个奇怪的解决办法。感谢更新…@MarkusWMahlberg..因为我们的代码是集群的(两台不同机器上的应用程序的两个实例),所以同步不会解决Java方面的问题..还有其他选择吗?