com.mongodb.client.model.DeleteOptions Java Examples

The following examples show how to use com.mongodb.client.model.DeleteOptions. 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: BasicInteractionTest.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test
void testSingleDocumentDeletionWithOptions() {
    ReactiveMongoDatabase database = client.getDatabase(DATABASE);
    ReactiveMongoCollection<Document> collection = database.getCollection(randomAlphaString(8));

    List<Document> documents = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
        documents.add(new Document("i", i));
    }
    collection.insertMany(documents).await().indefinitely();

    DeleteResult result = collection.deleteOne(eq("i", 10),
            new DeleteOptions().collation(
                    Collation.builder().locale("en").caseLevel(true).build()))
            .await().indefinitely();
    assertThat(result.getDeletedCount()).isEqualTo(1);
    assertThat(collection.find(eq("i", 10)).collectItems().first().await().indefinitely()).isNull();
    Long count = collection.countDocuments().await().indefinitely();
    assertThat(count).isEqualTo(99);
}
 
Example #2
Source File: BasicInteractionTest.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test
void testMultipleDocumentDeletionWithOptions() {
    ReactiveMongoDatabase database = client.getDatabase(DATABASE);
    ReactiveMongoCollection<Document> collection = database.getCollection(randomAlphaString(8));

    List<Document> documents = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
        documents.add(new Document("i", i));
    }
    collection.insertMany(documents).await().indefinitely();

    DeleteResult result = collection.deleteMany(gte("i", 90), new DeleteOptions().collation(
            Collation.builder().locale("en").caseLevel(true).build()))
            .await().indefinitely();
    assertThat(result.getDeletedCount()).isEqualTo(10);
    assertThat(collection.find(eq("i", 90)).collectItems().first().await().asOptional().indefinitely()).isEmpty();
    Long count = collection.countDocuments().await().indefinitely();
    assertThat(count).isEqualTo(90);
}
 
Example #3
Source File: MongoCollectionImpl.java    From mongo-java-driver-reactivestreams with Apache License 2.0 5 votes vote down vote up
@Override
public Publisher<DeleteResult> deleteMany(final Bson filter, final DeleteOptions options) {
    return new ObservableToPublisher<DeleteResult>(com.mongodb.async.client.Observables.observe(
            new Block<com.mongodb.async.SingleResultCallback<DeleteResult>>() {
                @Override
                public void apply(final com.mongodb.async.SingleResultCallback<DeleteResult> callback) {
                    wrapped.deleteMany(filter, options, callback);
                }
            }));
}
 
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<DeleteResult> deleteOne(final ClientSession clientSession, final Bson filter, final DeleteOptions options) {
    return new ObservableToPublisher<DeleteResult>(com.mongodb.async.client.Observables.observe(
            new Block<com.mongodb.async.SingleResultCallback<DeleteResult>>() {
                @Override
                public void apply(final com.mongodb.async.SingleResultCallback<DeleteResult> callback) {
                    wrapped.deleteOne(clientSession.getWrapped(), filter, options, callback);
                }
            }));
}
 
Example #5
Source File: MongoCollectionImpl.java    From mongo-java-driver-reactivestreams with Apache License 2.0 5 votes vote down vote up
@Override
public Publisher<DeleteResult> deleteOne(final Bson filter, final DeleteOptions options) {
    return new ObservableToPublisher<DeleteResult>(com.mongodb.async.client.Observables.observe(
            new Block<com.mongodb.async.SingleResultCallback<DeleteResult>>() {
                @Override
                public void apply(final com.mongodb.async.SingleResultCallback<DeleteResult> callback) {
                    wrapped.deleteOne(filter, options, callback);
                }
            }));
}
 
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<DeleteResult> deleteMany(final ClientSession clientSession, final Bson filter, final DeleteOptions options) {
    return new ObservableToPublisher<DeleteResult>(com.mongodb.async.client.Observables.observe(
            new Block<com.mongodb.async.SingleResultCallback<DeleteResult>>() {
                @Override
                public void apply(final com.mongodb.async.SingleResultCallback<DeleteResult> callback) {
                    wrapped.deleteMany(clientSession.getWrapped(), filter, options, callback);
                }
            }));
}
 
Example #7
Source File: MongoCollectionImpl.java    From mongo-java-driver-rx with Apache License 2.0 5 votes vote down vote up
@Override
public Observable<DeleteResult> deleteOne(final Bson filter, final DeleteOptions options) {
    return RxObservables.create(Observables.observe(new Block<SingleResultCallback<DeleteResult>>() {
        @Override
        public void apply(final SingleResultCallback<DeleteResult> callback) {
            wrapped.deleteOne(filter, options, callback);
        }
    }), observableAdapter);
}
 
Example #8
Source File: MongoCollectionImpl.java    From mongo-java-driver-rx with Apache License 2.0 5 votes vote down vote up
@Override
public Observable<DeleteResult> deleteMany(final Bson filter, final DeleteOptions options) {
    return RxObservables.create(Observables.observe(new Block<SingleResultCallback<DeleteResult>>() {
        @Override
        public void apply(final SingleResultCallback<DeleteResult> callback) {
            wrapped.deleteMany(filter, options, callback);
        }
    }), observableAdapter);
}
 
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<DeleteResult> deleteMany(final ClientSession clientSession, final Bson filter) {
    return deleteMany(clientSession, filter, new DeleteOptions());
}
 
Example #10
Source File: MongoCollectionImpl.java    From mongo-java-driver-reactivestreams with Apache License 2.0 4 votes vote down vote up
@Override
public Publisher<DeleteResult> deleteMany(final Bson filter) {
    return deleteMany(filter, new DeleteOptions());
}
 
Example #11
Source File: MongoCollectionImpl.java    From mongo-java-driver-reactivestreams with Apache License 2.0 4 votes vote down vote up
@Override
public Publisher<DeleteResult> deleteOne(final ClientSession clientSession, final Bson filter) {
    return deleteOne(clientSession, filter, new DeleteOptions());
}
 
Example #12
Source File: MongoCollectionImpl.java    From mongo-java-driver-reactivestreams with Apache License 2.0 4 votes vote down vote up
@Override
public Publisher<DeleteResult> deleteOne(final Bson filter) {
    return deleteOne(filter, new DeleteOptions());
}
 
Example #13
Source File: ReactiveMongoCollectionImpl.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public Uni<DeleteResult> deleteMany(ClientSession clientSession, Bson filter, DeleteOptions options) {
    return Wrappers.toUni(collection.deleteMany(clientSession, filter, options));
}
 
Example #14
Source File: ReactiveMongoCollectionImpl.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public Uni<DeleteResult> deleteMany(Bson filter, DeleteOptions options) {
    return Wrappers.toUni(collection.deleteMany(filter, options));
}
 
Example #15
Source File: ReactiveMongoCollectionImpl.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public Uni<DeleteResult> deleteOne(ClientSession clientSession, Bson filter, DeleteOptions options) {
    return Wrappers.toUni(collection.deleteOne(clientSession, filter, options));
}
 
Example #16
Source File: ReactiveMongoCollectionImpl.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public Uni<DeleteResult> deleteOne(Bson filter, DeleteOptions options) {
    return Wrappers.toUni(collection.deleteOne(filter, options));
}
 
Example #17
Source File: MongoCollection.java    From mongo-java-driver-reactivestreams with Apache License 2.0 2 votes vote down vote up
/**
 * Removes at most one document from the collection that matches the given filter.  If no documents match, the collection is not
 * modified.
 *
 * @param filter the query filter to apply the the delete operation
 * @param options the options to apply to the delete operation
 * @return a publisher with a single element the DeleteResult or with an com.mongodb.MongoException
 * @since 1.5
 */
Publisher<DeleteResult> deleteOne(Bson filter, DeleteOptions options);
 
Example #18
Source File: MongoCollection.java    From mongo-java-driver-reactivestreams with Apache License 2.0 2 votes vote down vote up
/**
 * Removes at most one document from the collection that matches the given filter.  If no documents match, the collection is not
 * modified.
 *
 * @param clientSession the client session with which to associate this operation
 * @param filter the query filter to apply the the delete operation
 * @param options the options to apply to the delete operation
 * @return a publisher with a single element the DeleteResult or with an com.mongodb.MongoException
 * @mongodb.server.release 3.6
 * @since 1.7
 */
Publisher<DeleteResult> deleteOne(ClientSession clientSession, Bson filter, DeleteOptions options);
 
Example #19
Source File: MongoCollection.java    From mongo-java-driver-reactivestreams with Apache License 2.0 2 votes vote down vote up
/**
 * Removes all documents from the collection that match the given query filter.  If no documents match, the collection is not modified.
 *
 * @param filter the query filter to apply the the delete operation
 * @param options the options to apply to the delete operation
 * @return a publisher with a single element the DeleteResult or with an com.mongodb.MongoException
 * @since 1.5
 */
Publisher<DeleteResult> deleteMany(Bson filter, DeleteOptions options);
 
Example #20
Source File: MongoCollection.java    From mongo-java-driver-reactivestreams with Apache License 2.0 2 votes vote down vote up
/**
 * Removes all documents from the collection that match the given query filter.  If no documents match, the collection is not modified.
 *
 * @param clientSession the client session with which to associate this operation
 * @param filter the query filter to apply the the delete operation
 * @param options the options to apply to the delete operation
 * @return a publisher with a single element the DeleteResult or with an com.mongodb.MongoException
 * @mongodb.server.release 3.6
 * @since 1.7
 */
Publisher<DeleteResult> deleteMany(ClientSession clientSession, Bson filter, DeleteOptions options);
 
Example #21
Source File: MongoCollection.java    From mongo-java-driver-rx with Apache License 2.0 2 votes vote down vote up
/**
 * Removes all documents from the collection that match the given query filter.  If no documents match, the collection is not modified.
 *
 * @param filter the query filter to apply the the delete operation
 * @param options the options to apply to the delete operation
 * @return an Observable with a single element the DeleteResult or with an com.mongodb.MongoException
 * @since 1.3
 */
Observable<DeleteResult> deleteMany(Bson filter, DeleteOptions options);
 
Example #22
Source File: ReactiveMongoCollection.java    From quarkus with Apache License 2.0 2 votes vote down vote up
/**
 * Removes at most one document from the collection that matches the given filter.
 * If no documents match, the collection is not modified.
 *
 * @param filter the query filter to apply the the delete operation
 * @param options the options to apply to the delete operation
 * @return a {@link Uni} receiving the {@link DeleteResult}, or propagating a {@link com.mongodb.MongoException} on
 *         failure.
 */
Uni<DeleteResult> deleteOne(Bson filter, DeleteOptions options);
 
Example #23
Source File: MongoCollection.java    From mongo-java-driver-rx with Apache License 2.0 2 votes vote down vote up
/**
 * Removes at most one document from the collection that matches the given filter.  If no documents match, the collection is not
 * modified.
 *
 * @param filter the query filter to apply the the delete operation
 * @param options the options to apply to the delete operation
 * @return an Observable with a single element the DeleteResult or with an com.mongodb.MongoException
 * @since 1.3
 */
Observable<DeleteResult> deleteOne(Bson filter, DeleteOptions options);
 
Example #24
Source File: ReactiveMongoCollection.java    From quarkus with Apache License 2.0 2 votes vote down vote up
/**
 * Removes all documents from the collection that match the given query filter. If no documents match, the
 * collection is not modified.
 *
 * @param clientSession the client session with which to associate this operation
 * @param filter the query filter to apply the the delete operation
 * @param options the options to apply to the delete operation
 * @return a {@link Uni} receiving the {@link DeleteResult}, or propagating a {@link com.mongodb.MongoException} on
 *         failure.
 */
Uni<DeleteResult> deleteMany(ClientSession clientSession, Bson filter, DeleteOptions options);
 
Example #25
Source File: ReactiveMongoCollection.java    From quarkus with Apache License 2.0 2 votes vote down vote up
/**
 * Removes all documents from the collection that match the given query filter. If no documents match, the
 * collection is not modified.
 *
 * @param filter the query filter to apply the the delete operation
 * @param options the options to apply to the delete operation
 * @return a {@link Uni} receiving the {@link DeleteResult}, or propagating a {@link com.mongodb.MongoException} on
 *         failure.
 */
Uni<DeleteResult> deleteMany(Bson filter, DeleteOptions options);
 
Example #26
Source File: ReactiveMongoCollection.java    From quarkus with Apache License 2.0 2 votes vote down vote up
/**
 * Removes at most one document from the collection that matches the given filter.
 * If no documents match, the collection is not modified.
 *
 * @param clientSession the client session with which to associate this operation
 * @param filter the query filter to apply the the delete operation
 * @param options the options to apply to the delete operation
 * @return a {@link Uni} receiving the {@link DeleteResult}, or propagating a {@link com.mongodb.MongoException} on
 *         failure.
 */
Uni<DeleteResult> deleteOne(ClientSession clientSession, Bson filter, DeleteOptions options);