/** * Configures this modifier so that new (updated) version of document will be returned in * case of successful update. * @see #returningOld() * @return {@code this} modifier for chained invocation */ // safe unchecked: we expect I to be a self type @SuppressWarnings("unchecked") public final M returningNew() { options.returnDocument(ReturnDocument.AFTER); return (M) this; }
/** * Configures this modifier so that old (not updated) version of document will be returned in * case of successful update. * This is default behavior so it may be called only for explanatory reasons. * @see #returningNew() * @return {@code this} modifier for chained invocation */ // safe unchecked: we expect I to be a self type @SuppressWarnings("unchecked") public final M returningOld() { options.returnDocument(ReturnDocument.BEFORE); return (M) this; }
private FindOneAndReplaceOptions convertToFindOneAndReplaceOptions(FindAndReplaceOptions options, Document fields, Document sort) { FindOneAndReplaceOptions result = new FindOneAndReplaceOptions().collation(collation); result = result.projection(fields).sort(sort).upsert(options.isUpsert()); if (options.isReturnNew()) { result = result.returnDocument(ReturnDocument.AFTER); } else { result = result.returnDocument(ReturnDocument.BEFORE); } return result; } }
@Override public Document doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException { FindOneAndReplaceOptions opts = new FindOneAndReplaceOptions(); opts.sort(sort); opts.collation(collation); opts.projection(fields); if (options.isUpsert()) { opts.upsert(true); } if (options.isReturnNew()) { opts.returnDocument(ReturnDocument.AFTER); } return collection.findOneAndReplace(query, update, opts); } }
private FindOneAndReplaceOptions convertToFindOneAndReplaceOptions(FindAndReplaceOptions options, Document fields, Document sort) { FindOneAndReplaceOptions result = new FindOneAndReplaceOptions().collation(collation); result = result.projection(fields).sort(sort).upsert(options.isUpsert()); if (options.isReturnNew()) { result = result.returnDocument(ReturnDocument.AFTER); } else { result = result.returnDocument(ReturnDocument.BEFORE); } return result; } }
@Override public Document doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException { FindOneAndReplaceOptions opts = new FindOneAndReplaceOptions(); opts.sort(sort); opts.collation(collation); opts.projection(fields); if (options.isUpsert()) { opts.upsert(true); } if (options.isReturnNew()) { opts.returnDocument(ReturnDocument.AFTER); } return collection.findOneAndReplace(query, update, opts); } }
/** * Configures this modifier so that new (updated) version of document will be returned in * case of successful update. * @see #returningOld() * @return {@code this} modifier for chained invocation */ // safe unchecked: we expect I to be a self type @SuppressWarnings("unchecked") public final M returningNew() { options.returnDocument(ReturnDocument.AFTER); return (M) this; }
/** * Configures this modifier so that old (not updated) version of document will be returned in * case of successful update. * This is default behavior so it may be called only for explanatory reasons. * @see #returningNew() * @return {@code this} modifier for chained invocation */ // safe unchecked: we expect I to be a self type @SuppressWarnings("unchecked") public final M returningOld() { options.returnDocument(ReturnDocument.BEFORE); return (M) this; }
public void updateIfMatch(final V value, final String eTag) { Bson query = and(eq(AbstractMongoRepository.ID, keyOf(value)), eq(ETAG, eTag)); Document updatedETaggable = collection().findOneAndReplace(query, encode(value), new FindOneAndReplaceOptions().returnDocument(AFTER)); if (isNull(updatedETaggable)) { Optional<V> findById = findOne(keyOf(value)); if (findById.isPresent()) { throw new ConcurrentModificationException("Entity concurrently modified: " + keyOf(value)); } throw new NotFoundException("Entity does not exist: " + keyOf(value)); } }
final Bson query = and(eq(AbstractMongoRepository.ID, key), eq(ETAG, eTag)); final Document updatedETaggable = collectionWithWriteTimeout(maxTime, timeUnit).findOneAndReplace(query, encode(value), new FindOneAndReplaceOptions().returnDocument(AFTER)); if (isNull(updatedETaggable)) { final boolean documentExists = collection()
final Bson query = and(eq(AbstractMongoRepository.ID, key), eq(ETAG, eTag)); final Document updatedETaggable = collectionWithWriteTimeout(maxTime, timeUnit).findOneAndReplace(query, encode(value), new FindOneAndReplaceOptions().returnDocument(AFTER)); if (isNull(updatedETaggable)) { final boolean documentExists = collection()
.projection(projection) .upsert(upsert) .returnDocument(returnNew ? ReturnDocument.AFTER : ReturnDocument.BEFORE); return dbCollection.findOneAndReplace(query, update, findOneAndReplaceOptions); } else {
.upsert(true).returnDocument(ReturnDocument.AFTER); .upsert(false).returnDocument(ReturnDocument.AFTER);