use of com.mongodb.client.model.FindOneAndUpdateOptions in project engine by Lumeer.
the class MongoDbStorage method getNextSequenceNo.
@Override
public synchronized int getNextSequenceNo(final String collectionName, final String indexAttribute, final String index) {
final FindOneAndUpdateOptions options = new FindOneAndUpdateOptions();
options.returnDocument(ReturnDocument.AFTER);
final Document doc = database.getCollection(collectionName).findOneAndUpdate(eq(indexAttribute, index), inc("seq", 1), options);
if (doc == null) {
// the sequence did not exist
resetSequence(collectionName, indexAttribute, index);
return 0;
} else {
return doc.getInteger("seq");
}
}
Aggregations