Source:
<code>protected WriteResult doUpdate(final String collectionName, final Query query, final Update update, final Class<?> entityClass, final boolean upsert, final boolean multi) { return execute(collectionName, new CollectionCallback<WriteResult>() { public WriteResult doInCollection(DBCollection collection) throws MongoException, DataAccessException { MongoPersistentEntity<?> entity = entityClass == null ? null : getPersistentEntity(entityClass); increaseVersionForUpdateIfNecessary(entity, update); DBObject queryObj = query == null ? new BasicDBObject() : queryMapper.getMappedObject(query.getQueryObject(), entity); DBObject updateObj = update == null ? new BasicDBObject() : updateMapper.getMappedObject( update.getUpdateObject(), entity); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Calling update using query: " + queryObj + " and update: " + updateObj + " in collection: " + collectionName); } MongoAction mongoAction = new MongoAction(writeConcern, MongoActionOperation.UPDATE, collectionName, entityClass, updateObj, queryObj); WriteConcern writeConcernToUse = prepareWriteConcern(mongoAction); WriteResult writeResult = writeConcernToUse == null ? collection.update(queryObj, updateObj, upsert, multi) : collection.update(queryObj, updateObj, upsert, multi, writeConcernToUse); if (entity != null && entity.hasVersionProperty() && !multi) { <START> if (writeResult.getN() == 0 && dbObjectContainsProperty(queryObj, entity.getVersionProperty())) { <END> throw new OptimisticLockingFailureException("Optimistic lock exception on saving entity: " + updateObj.toMap().toString() + " to collection " + collectionName); } } handleAnyWriteResultErrors(writeResult, queryObj, MongoActionOperation.UPDATE); return writeResult; } }); }</code><technical_language>understand this: do need additional guard here? would've a valid execution (query object) would've erroneously exception fix</technical_language>

Target:
protected WriteResult doUpdate(final String collectionName, final Query query, final Update update, final Class<?> entityClass, final boolean upsert, final boolean multi) { return execute(collectionName, new CollectionCallback<WriteResult>() { public WriteResult doInCollection(DBCollection collection) throws MongoException, DataAccessException { MongoPersistentEntity<?> entity = entityClass == null ? null : getPersistentEntity(entityClass); increaseVersionForUpdateIfNecessary(entity, update); DBObject queryObj = query == null ? new BasicDBObject() : queryMapper.getMappedObject(query.getQueryObject(), entity); DBObject updateObj = update == null ? new BasicDBObject() : updateMapper.getMappedObject( update.getUpdateObject(), entity); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Calling update using query: " + queryObj + " and update: " + updateObj + " in collection: " + collectionName); } MongoAction mongoAction = new MongoAction(writeConcern, MongoActionOperation.UPDATE, collectionName, entityClass, updateObj, queryObj); WriteConcern writeConcernToUse = prepareWriteConcern(mongoAction); WriteResult writeResult = writeConcernToUse == null ? collection.update(queryObj, updateObj, upsert, multi) : collection.update(queryObj, updateObj, upsert, multi, writeConcernToUse); if (entity != null && entity.hasVersionProperty() && !multi) { if (writeResult.getN() == 0 && dbObjectContainsVersionProperty(queryObj, entity)) { throw new OptimisticLockingFailureException("Optimistic lock exception on saving entity: " + updateObj.toMap().toString() + " to collection " + collectionName); } } handleAnyWriteResultErrors(writeResult, queryObj, MongoActionOperation.UPDATE); return writeResult; } }); }