Thought the WriteResult.getLastError()
should return null
, if the delete
operation was successful.
It returns this
{ "n" : 1 , "connectionId" : 200 , "wtime" : 0 , "err" : null , "ok" : 1.0}
The BatchData
Document
was deleted successfully, but getLastError()
is not null
.
How should I write the code to know, if the delete was unsuccessful, in the following snippet:
try {
Query<BatchData> queryDeleteBatchData = mongo.createQuery(BatchData.class);
queryDeleteBatchData.field("uuid").equal(theBatch.uuid);
queryDeleteBatchData.field("senderUuid").equal(on.uuid);
WriteResult del = mongo.delete(queryDeleteBatchData);
if(del.getLastError() != null){
logger.error("ERROR");
}
} catch (Exception e) {
logger.error("ERROR" );
}
The getLastError()
command is doing the correct thing. It's telling you that the action was successful (ok:1.0
) and that no error occurred ("err":null
).
For more details check out the recently updated docs.
getLastError()
also has some functionality related to journaling and replication that you may want to investigate.
Edit:
In response to the first comment:
...
if(del.getLastError().ok != 1.0){
logger.error("ERROR");
}
} catch (Exception e) {
logger.error("ERROR" );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With