mongo数据库写入异常唯一key重复

发布时间:2024年01月12日

问题提示:
DuplicateKeyException: Bulk

完整提示链接:
org.springframework.data.mongodb.core.MongoTemplate[2554] find using query: { “uid” : { “$gt” : -1}} fields: Document{{}} for class: class cn.benewtech.reading.domain.origin.knowledge.OriginEnAudio in collection: enaudios
2024-01-12 17:01:01,784 [main] INFO
2024-01-12 17:01:02,054 [main] DEBUG org.springframework.data.mongodb.core.MongoTemplate[1481] Inserting list of Documents containing 500 items

org.springframework.dao.DuplicateKeyException: Bulk write operation error on server . Write errors: [BulkWriteError{index=1, code=11000, message=‘E11000 duplicate key error collection: ntt-reading.enworddefinitionaudios index: uid dup key: { : null }’, details={}}]. ; nested exception is com.mongodb.MongoBulkWriteException: Bulk write operation error on server 机器IP地址. Write errors: [BulkWriteError{index=1, code=11000, message=‘E11000 duplicate key error collection: ntt-reading.tablename index: uid dup key: { : null }’, details={}}].

at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:111)
at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2906)
at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:557)
at org.springframework.data.mongodb.core.MongoTemplate.insertDocumentList(MongoTemplate.java:1484)
at org.springframework.data.mongodb.core.MongoTemplate.doInsertBatch(MongoTemplate.java:1348)
at org.springframework.data.mongodb.core.MongoTemplate.doInsertAll(MongoTemplate.java:1317)
at org.springframework.data.mongodb.core.MongoTemplate.insertAll(MongoTemplate.java:1290)
at cn.benewtech.reading.admin.data.sync.knowledge.EnWordDefinitionAudioSync.doEnAudio2enWordDefinitionAudio(EnWordDefinitionAudioSync.java:84)
at cn.benewtech.reading.admin.data.sync.knowledge.EnWordDefinitionAudioSync.enEnAudio2enWordDefinitionAudio(EnWordDefinitionAudioSync.java:51)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)

Caused by: com.mongodb.MongoBulkWriteException: Bulk write operation error on server 机器IP地址. Write errors: [BulkWriteError{index=1, code=11000, message=‘E11000 duplicate key error collection: ntt-reading.tablename index: uid dup key: { : null }’, details={}}].
at com.mongodb.internal.connection.BulkWriteBatchCombiner.getError(BulkWriteBatchCombiner.java:167)
at com.mongodb.internal.connection.BulkWriteBatchCombiner.throwOnError(BulkWriteBatchCombiner.java:191)
at com.mongodb.internal.connection.BulkWriteBatchCombiner.getResult(BulkWriteBatchCombiner.java:136)
at com.mongodb.internal.operation.BulkWriteBatch.getResult(BulkWriteBatch.java:224)
at com.mongodb.internal.operation.MixedBulkWriteOperation.executeBulkWriteBatch(MixedBulkWriteOperation.java:363)
at com.mongodb.internal.operation.MixedBulkWriteOperation.lambda$execute 2 ( M i x e d B u l k W r i t e O p e r a t i o n . j a v a : 260 ) a t c o m . m o n g o d b . i n t e r n a l . o p e r a t i o n . O p e r a t i o n H e l p e r . l a m b d a 2(MixedBulkWriteOperation.java:260) at com.mongodb.internal.operation.OperationHelper.lambda 2(MixedBulkWriteOperation.java:260)atcom.mongodb.internal.operation.OperationHelper.lambdawithSourceAndConnection 2 ( O p e r a t i o n H e l p e r . j a v a : 564 ) a t c o m . m o n g o d b . i n t e r n a l . o p e r a t i o n . O p e r a t i o n H e l p e r . w i t h S u p p l i e d R e s o u r c e ( O p e r a t i o n H e l p e r . j a v a : 589 ) a t c o m . m o n g o d b . i n t e r n a l . o p e r a t i o n . O p e r a t i o n H e l p e r . l a m b d a 2(OperationHelper.java:564) at com.mongodb.internal.operation.OperationHelper.withSuppliedResource(OperationHelper.java:589) at com.mongodb.internal.operation.OperationHelper.lambda 2(OperationHelper.java:564)atcom.mongodb.internal.operation.OperationHelper.withSuppliedResource(OperationHelper.java:589)atcom.mongodb.internal.operation.OperationHelper.lambdawithSourceAndConnection 3 ( O p e r a t i o n H e l p e r . j a v a : 563 ) a t c o m . m o n g o d b . i n t e r n a l . o p e r a t i o n . O p e r a t i o n H e l p e r . w i t h S u p p l i e d R e s o u r c e ( O p e r a t i o n H e l p e r . j a v a : 589 ) a t c o m . m o n g o d b . i n t e r n a l . o p e r a t i o n . O p e r a t i o n H e l p e r . w i t h S o u r c e A n d C o n n e c t i o n ( O p e r a t i o n H e l p e r . j a v a : 562 ) a t c o m . m o n g o d b . i n t e r n a l . o p e r a t i o n . M i x e d B u l k W r i t e O p e r a t i o n . l a m b d a 3(OperationHelper.java:563) at com.mongodb.internal.operation.OperationHelper.withSuppliedResource(OperationHelper.java:589) at com.mongodb.internal.operation.OperationHelper.withSourceAndConnection(OperationHelper.java:562) at com.mongodb.internal.operation.MixedBulkWriteOperation.lambda 3(OperationHelper.java:563)atcom.mongodb.internal.operation.OperationHelper.withSuppliedResource(OperationHelper.java:589)atcom.mongodb.internal.operation.OperationHelper.withSourceAndConnection(OperationHelper.java:562)atcom.mongodb.internal.operation.MixedBulkWriteOperation.lambdaexecute 3 ( M i x e d B u l k W r i t e O p e r a t i o n . j a v a : 232 ) a t c o m . m o n g o d b . i n t e r n a l . a s y n c . f u n c t i o n . R e t r y i n g S y n c S u p p l i e r . g e t ( R e t r y i n g S y n c S u p p l i e r . j a v a : 65 ) a t c o m . m o n g o d b . i n t e r n a l . o p e r a t i o n . M i x e d B u l k W r i t e O p e r a t i o n . e x e c u t e ( M i x e d B u l k W r i t e O p e r a t i o n . j a v a : 268 ) a t c o m . m o n g o d b . i n t e r n a l . o p e r a t i o n . M i x e d B u l k W r i t e O p e r a t i o n . e x e c u t e ( M i x e d B u l k W r i t e O p e r a t i o n . j a v a : 84 ) a t c o m . m o n g o d b . c l i e n t . i n t e r n a l . M o n g o C l i e n t D e l e g a t e 3(MixedBulkWriteOperation.java:232) at com.mongodb.internal.async.function.RetryingSyncSupplier.get(RetryingSyncSupplier.java:65) at com.mongodb.internal.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:268) at com.mongodb.internal.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:84) at com.mongodb.client.internal.MongoClientDelegate 3(MixedBulkWriteOperation.java:232)atcom.mongodb.internal.async.function.RetryingSyncSupplier.get(RetryingSyncSupplier.java:65)atcom.mongodb.internal.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:268)atcom.mongodb.internal.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:84)atcom.mongodb.client.internal.MongoClientDelegateDelegateOperationExecutor.execute(MongoClientDelegate.java:212)
at com.mongodb.client.internal.MongoCollectionImpl.executeInsertMany(MongoCollectionImpl.java:499)
at com.mongodb.client.internal.MongoCollectionImpl.insertMany(MongoCollectionImpl.java:481)
at com.mongodb.client.internal.MongoCollectionImpl.insertMany(MongoCollectionImpl.java:476)
at org.springframework.data.mongodb.core.MongoTemplate.lambda$insertDocumentList$17(MongoTemplate.java:1491)
at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:555)
… 39 more

文章来源:https://blog.csdn.net/m0_55284524/article/details/135557902
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。