com.mongodb.client.model.FindOneAndDeleteOptions Java Examples

The following examples show how to use com.mongodb.client.model.FindOneAndDeleteOptions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Repositories.java    From immutables with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes and returns first matching document. Returns {@link Optional#absent()} if none
 * documents matches.
 * @return future of optional matching deleted document.
 */
public FluentFuture<Optional<T>> deleteFirst() {
  checkState(numberToSkip == 0, "Cannot use .skip() with .deleteFirst()");
  FindOneAndDeleteOptions options = new FindOneAndDeleteOptions();
  options.sort(convertToBson(ordering));
  return repository.doFindOneAndDelete(criteria, options);
}
 
Example #2
Source File: Repositories.java    From immutables with Apache License 2.0 5 votes vote down vote up
protected final FluentFuture<Optional<T>> doFindOneAndDelete(
        final Constraints.ConstraintHost criteria,
        final FindOneAndDeleteOptions options) {

  checkNotNull(criteria, "criteria");
  checkNotNull(options, "options");

  return submit(new Callable<Optional<T>>() {
    @Override
    public Optional<T> call() throws Exception {
      @Nullable T result = collection().findOneAndDelete(convertToBson(criteria), options);
      return Optional.fromNullable(result);
    }
  });
}
 
Example #3
Source File: CollectionManagementTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
void findAndDelete() {
    ReactiveMongoDatabase database = client.getDatabase(DATABASE);
    ReactiveMongoCollection<Document> collection = database.getCollection("test");

    CompletableFuture.allOf(
            collection
                    .insertOne(new Document("id", 1).append("name", "superman").append("type", "heroes")
                            .append("stars", 5))
                    .subscribeAsCompletionStage(),
            collection.insertOne(
                    new Document("id", 2).append("name", "batman").append("type", "heroes").append("stars", 4))
                    .subscribeAsCompletionStage(),
            collection
                    .insertOne(new Document("id", 3).append("name", "frogman").append("type", "villain")
                            .append("stars", 1))
                    .subscribeAsCompletionStage(),
            collection.insertOne(
                    new Document("id", 4).append("name", "joker").append("type", "villain").append("stars", 5))
                    .subscribeAsCompletionStage())
            .join();

    Document frogman = collection.findOneAndDelete(new Document("id", 3)).await().indefinitely();
    Document superman = collection
            .findOneAndDelete(new Document("id", 1), new FindOneAndDeleteOptions().sort(new Document("id", 1)))
            .await().indefinitely();

    assertThat(frogman).contains(entry("stars", 1), entry("name", "frogman"));
    assertThat(superman).contains(entry("stars", 5), entry("name", "superman"));

}
 
Example #4
Source File: MongoCollectionImpl.java    From mongo-java-driver-reactivestreams with Apache License 2.0 5 votes vote down vote up
@Override
public Publisher<TDocument> findOneAndDelete(final ClientSession clientSession, final Bson filter,
                                             final FindOneAndDeleteOptions options) {
    return new ObservableToPublisher<TDocument>(com.mongodb.async.client.Observables.observe(
            new Block<com.mongodb.async.SingleResultCallback<TDocument>>() {
                @Override
                public void apply(final com.mongodb.async.SingleResultCallback<TDocument> callback) {
                    wrapped.findOneAndDelete(clientSession.getWrapped(), filter, options, callback);
                }
            }));
}
 
Example #5
Source File: MongoCollectionImpl.java    From mongo-java-driver-rx with Apache License 2.0 5 votes vote down vote up
@Override
public Observable<TDocument> findOneAndDelete(final Bson filter, final FindOneAndDeleteOptions options) {
    return RxObservables.create(Observables.observe(new Block<SingleResultCallback<TDocument>>() {
        @Override
        public void apply(final SingleResultCallback<TDocument> callback) {
            wrapped.findOneAndDelete(filter, options, callback);
        }
    }), observableAdapter);
}
 
Example #6
Source File: MongoCollectionImpl.java    From mongo-java-driver-reactivestreams with Apache License 2.0 5 votes vote down vote up
@Override
public Publisher<TDocument> findOneAndDelete(final Bson filter, final FindOneAndDeleteOptions options) {
    return new ObservableToPublisher<TDocument>(com.mongodb.async.client.Observables.observe(
            new Block<com.mongodb.async.SingleResultCallback<TDocument>>() {
                @Override
                public void apply(final com.mongodb.async.SingleResultCallback<TDocument> callback) {
                    wrapped.findOneAndDelete(filter, options, callback);
                }
            }));
}
 
Example #7
Source File: MongoCollectionImpl.java    From mongo-java-driver-reactivestreams with Apache License 2.0 4 votes vote down vote up
@Override
public Publisher<TDocument> findOneAndDelete(final Bson filter) {
    return findOneAndDelete(filter, new FindOneAndDeleteOptions());
}
 
Example #8
Source File: OptionsTest.java    From morphia with Apache License 2.0 4 votes vote down vote up
@Test
public void findAndDeleteOptions() {
    scan(FindOneAndDeleteOptions.class, FindAndDeleteOptions.class, true, List.of(WriteConcern.class));
}
 
Example #9
Source File: MongoCollectionImpl.java    From mongo-java-driver-reactivestreams with Apache License 2.0 4 votes vote down vote up
@Override
public Publisher<TDocument> findOneAndDelete(final ClientSession clientSession, final Bson filter) {
    return findOneAndDelete(clientSession, filter, new FindOneAndDeleteOptions());
}
 
Example #10
Source File: MongoCollectionImpl.java    From mongo-java-driver-rx with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<TDocument> findOneAndDelete(final Bson filter) {
    return findOneAndDelete(filter, new FindOneAndDeleteOptions());
}
 
Example #11
Source File: ReactiveMongoCollectionImpl.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public Uni<T> findOneAndDelete(ClientSession clientSession, Bson filter, FindOneAndDeleteOptions options) {
    return Wrappers.toUni(collection.findOneAndDelete(clientSession, filter, options));
}
 
Example #12
Source File: ReactiveMongoCollectionImpl.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public Uni<T> findOneAndDelete(Bson filter, FindOneAndDeleteOptions options) {
    return Wrappers.toUni(collection.findOneAndDelete(filter, options));
}
 
Example #13
Source File: ReactiveMongoCollection.java    From quarkus with Apache License 2.0 2 votes vote down vote up
/**
 * Atomically find a document and remove it.
 *
 * @param filter the query filter to find the document with
 * @param options the options to apply to the operation
 * @return a {@link Uni} completed with the document that was removed. If no documents matched the query filter,
 *         then the uni is completed with {@code null}.
 */
Uni<T> findOneAndDelete(Bson filter, FindOneAndDeleteOptions options);
 
Example #14
Source File: MongoCollection.java    From mongo-java-driver-rx with Apache License 2.0 2 votes vote down vote up
/**
 * Atomically find a document and remove it.
 *
 * @param filter  the query filter to find the document with
 * @param options the options to apply to the operation
 * @return an Observable with a single element the document that was removed.  If no documents matched the query filter, then the
 * observer will complete without emitting any items
 */
Observable<TDocument> findOneAndDelete(Bson filter, FindOneAndDeleteOptions options);
 
Example #15
Source File: MongoCollection.java    From mongo-java-driver-reactivestreams with Apache License 2.0 2 votes vote down vote up
/**
 * Atomically find a document and remove it.
 *
 * @param filter  the query filter to find the document with
 * @param options the options to apply to the operation
 * @return a publisher with a single element the document that was removed.  If no documents matched the query filter, then null will be
 * returned
 */
Publisher<TDocument> findOneAndDelete(Bson filter, FindOneAndDeleteOptions options);
 
Example #16
Source File: MongoCollection.java    From mongo-java-driver-reactivestreams with Apache License 2.0 2 votes vote down vote up
/**
 * Atomically find a document and remove it.
 *
 * @param clientSession the client session with which to associate this operation
 * @param filter  the query filter to find the document with
 * @param options the options to apply to the operation
 * @return a publisher with a single element the document that was removed.  If no documents matched the query filter, then null will be
 * returned
 * @mongodb.server.release 3.6
 * @since 1.7
 */
Publisher<TDocument> findOneAndDelete(ClientSession clientSession, Bson filter, FindOneAndDeleteOptions options);
 
Example #17
Source File: ReactiveMongoCollection.java    From quarkus with Apache License 2.0 2 votes vote down vote up
/**
 * Atomically find a document and remove it.
 *
 * @param clientSession the client session with which to associate this operation
 * @param filter the query filter to find the document with
 * @param options the options to apply to the operation
 * @return a {@link Uni} completed with the document that was removed. If no documents matched the query filter,
 *         then the uni is completed with {@code null}.
 */
Uni<T> findOneAndDelete(ClientSession clientSession, Bson filter, FindOneAndDeleteOptions options);