upsert
mongodb
中我的应用程序遇到以下错误:
异常
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]
参考
搜索后,确定JIRA
中有两个未解决的问题:
https://jira.mongodb.org/browse/SERVER-14322
https://jira.mongodb.org/browse/SERVER-20022
注意:我们的应用程序是多线程的。两个不同的线程正在执行批量upsert。
问题
在Java中应用程序端编码以避免失败并使用适当的值更新文档有什么替代方法?