Example usage for com.mongodb.async.client MongoCollection findOneAndDelete

List of usage examples for com.mongodb.async.client MongoCollection findOneAndDelete

Introduction

In this page you can find the example usage for com.mongodb.async.client MongoCollection findOneAndDelete.

Prototype

void findOneAndDelete(ClientSession clientSession, Bson filter, SingleResultCallback<TDocument> callback);

Source Link

Document

Atomically find a document and remove it.

Usage

From source file:io.vertx.ext.mongo.impl.MongoClientImpl.java

License:Open Source License

@Override
public io.vertx.ext.mongo.MongoClient findOneAndDeleteWithOptions(String collection, JsonObject query,
        FindOptions findOptions, Handler<AsyncResult<JsonObject>> resultHandler) {
    requireNonNull(collection, "collection cannot be null");
    requireNonNull(query, "query cannot be null");
    requireNonNull(findOptions, "find options cannot be null");
    requireNonNull(resultHandler, "resultHandler cannot be null");

    JsonObject encodedQuery = encodeKeyWhenUseObjectId(query);

    Bson bquery = wrap(encodedQuery);//from w  ww . ja va2  s.  co m
    FindOneAndDeleteOptions foadOptions = new FindOneAndDeleteOptions();
    foadOptions.sort(wrap(findOptions.getSort()));
    foadOptions.projection(wrap(findOptions.getFields()));

    MongoCollection<JsonObject> coll = getCollection(collection);
    coll.findOneAndDelete(bquery, foadOptions, wrapCallback(resultHandler));
    return this;
}