I am using the following piece of code to update a token field in a collection -
@Override
public TestObject issueToken(long id, String objectId) {
Query query = new Query();
Criteria criteria = new Criteria("_id").is(new ObjectId(objectId));
query.addCriteria(criteria);
Update update = new Update();
update.inc("lastIssuedTokenNo",1);
FindAndModifyOptions options = new FindAndModifyOptions();
options.upsert(false);
options.returnNew(true);
Testobject tokenIssuedObject = mongoTemplate.findAndModify(
query,update,options,
Testobject.class
);
if(ObjectUtils.isEmpty(tokenIssuedObject)) throw new ObjectRuntimeException(ErrorCodes.OBJECT_NOT_FOUND);
return tokenIssuedObject;
}
I have found few cases where this method is called and returned object doesn’t have the token value updated , what could be the possible reason for this?