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

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

Introduction

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

Prototype

void updateOne(ClientSession clientSession, Bson filter, List<? extends Bson> update,
        SingleResultCallback<UpdateResult> callback);

Source Link

Document

Update a single document in the collection according to the specified arguments.

Usage

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

License:Open Source License

@Override
public io.vertx.ext.mongo.MongoClient updateCollectionWithOptions(String collection, JsonObject query,
        JsonObject update, UpdateOptions options, Handler<AsyncResult<MongoClientUpdateResult>> resultHandler) {
    requireNonNull(collection, "collection cannot be null");
    requireNonNull(query, "query cannot be null");
    requireNonNull(update, "update cannot be null");
    requireNonNull(options, "options cannot be null");
    requireNonNull(resultHandler, "resultHandler cannot be null");

    MongoCollection<JsonObject> coll = getCollection(collection, options.getWriteOption());
    Bson bquery = wrap(encodeKeyWhenUseObjectId(query));
    Bson bupdate = wrap(encodeKeyWhenUseObjectId(update));
    if (options.isMulti()) {
        coll.updateMany(bquery, bupdate, mongoUpdateOptions(options), toMongoClientUpdateResult(resultHandler));
    } else {//from ww  w  .j  av a  2s.com
        coll.updateOne(bquery, bupdate, mongoUpdateOptions(options), toMongoClientUpdateResult(resultHandler));
    }
    return this;
}