Open
Description
From the docs, in the example for Optimistic Locking:
- Try to update the previously loaded document that still has
version = 0
. The operation fails with anOptimisticLockingFailureException
, as the currentversion
is1
.
This is inaccurate. In this specific case, where the version number of the document to be saved is (current version - 1)
, the actual exception thrown in practice is something like this:
com.mongodb.MongoWriteException: Write operation error on server localhost:27017. Write error: WriteError{code=11000, message='E11000 duplicate key error collection: database.collection index: _id_ dup key: { _id: "key" }', details={}}.
at com.mongodb.client.internal.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:1123)
at com.mongodb.client.internal.MongoCollectionImpl.executeInsertOne(MongoCollectionImpl.java:498)
at com.mongodb.client.internal.MongoCollectionImpl.insertOne(MongoCollectionImpl.java:481)
at com.mongodb.client.internal.MongoCollectionImpl.insertOne(MongoCollectionImpl.java:475)
at org.springframework.data.mongodb.core.MongoTemplate.lambda$insertDocument$17(MongoTemplate.java:1564)
at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:607)
at org.springframework.data.mongodb.core.MongoTemplate.insertDocument(MongoTemplate.java:1558)
at org.springframework.data.mongodb.core.MongoTemplate.doInsert(MongoTemplate.java:1356)
Version: 4.5.0
If you need a repro repo, please let me know.