-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 3.8.2
-
Component/s: Write Operations
-
None
-
(copied to CRM)
mongodb-driver-sync” (v3.8.2)
A `MongoCommandException` is thrown in `replaceOne` when a write concern cannot be fulfilled. But the Javadocs say it should be a `MongoWriteConcernException `
An example stacktrace:
com.mongodb.MongoCommandException: Command failed with error 64 (WriteConcernFailed): 'waiting for replication timed out; Error details: { wtimeout: true }' on server <HOST>:<p>. The full response is { "ok" : 0.0, "errmsg" : "waiting for replication timed out; Error details: { wtimeout: true }", "code" : 64, "codeName" : "WriteConcernFailed", "operationTime" : { "$timestamp" : { "t" : 1555309144, "i" : 1 } }, "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1555309144, "i" : 1 } }, "signature" : { "hash" : { "$binary" : "0oD+9Fb/yWy62TNt56fQ821auf8=", "$type" : "00" }, "keyId" : { "$numberLong" : "6634436738045444126" } } } } at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:179) ~[mongodb-driver-core-3.8.2.jar:na] at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:293) ~[mongodb-driver-core-3.8.2.jar:na] at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:255) ~[mongodb-driver-core-3.8.2.jar:na] at com.mongodb.internal.connection.UsageTrackingInternalConnection.sendAndReceive(UsageTrackingInternalConnection.java:99) ~[mongodb-driver-core-3.8.2.jar:na] at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.sendAndReceive(DefaultConnectionPool.java:444) ~[mongodb-driver-core-3.8.2.jar:na] at com.mongodb.internal.connection.CommandProtocolImpl.execute(CommandProtocolImpl.java:72) ~[mongodb-driver-core-3.8.2.jar:na] at com.mongodb.internal.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:200) ~[mongodb-driver-core-3.8.2.jar:na] at com.mongodb.internal.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:269) ~[mongodb-driver-core-3.8.2.jar:na] at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:131) ~[mongodb-driver-core-3.8.2.jar:na] at com.mongodb.operation.MixedBulkWriteOperation.executeCommand(MixedBulkWriteOperation.java:418) ~[mongodb-driver-core-3.8.2.jar:na] at com.mongodb.operation.MixedBulkWriteOperation.executeBulkWriteBatch(MixedBulkWriteOperation.java:256) ~[mongodb-driver-core-3.8.2.jar:na] at com.mongodb.operation.MixedBulkWriteOperation.access$700(MixedBulkWriteOperation.java:67) ~[mongodb-driver-core-3.8.2.jar:na] at com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:200) ~[mongodb-driver-core-3.8.2.jar:na] at com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:191) ~[mongodb-driver-core-3.8.2.jar:na] at com.mongodb.operation.OperationHelper.withReleasableConnection(OperationHelper.java:424) ~[mongodb-driver-core-3.8.2.jar:na] at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:191) ~[mongodb-driver-core-3.8.2.jar:na] at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:67) ~[mongodb-driver-core-3.8.2.jar:na] at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:193) ~[mongodb-driver-sync-3.8.2.jar:na] at com.mongodb.client.internal.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:960) ~[mongodb-driver-sync-3.8.2.jar:na] at com.mongodb.client.internal.MongoCollectionImpl.executeReplaceOne(MongoCollectionImpl.java:602) ~[mongodb-driver-sync-3.8.2.jar:na] at com.mongodb.client.internal.MongoCollectionImpl.replaceOne(MongoCollectionImpl.java:578) ~[mongodb-driver-sync-3.8.2.jar:na]
There seem to be at least two solutions:
- Update the Javadocs
- Catch this MongoCommandException and wrap in MongoWriteConcernException