Example usage for com.mongodb BulkWriteRequestBuilder updateOne

List of usage examples for com.mongodb BulkWriteRequestBuilder updateOne

Introduction

In this page you can find the example usage for com.mongodb BulkWriteRequestBuilder updateOne.

Prototype

public void updateOne(final DBObject update) 

Source Link

Document

Adds a request to update one document in the collection that matches the query with which this builder was created.

Usage

From source file:org.springframework.data.mongodb.core.DefaultBulkOperations.java

License:Apache License

/**
 * Performs update and upsert bulk operations.
 * //from   www  .  ja va2  s .com
 * @param query the {@link Query} to determine documents to update.
 * @param update the {@link Update} to perform, must not be {@literal null}.
 * @param upsert whether to upsert.
 * @param multi whether to issue a multi-update.
 * @return the {@link BulkOperations} with the update registered.
 */
private BulkOperations update(Query query, Update update, boolean upsert, boolean multi) {

    Assert.notNull(query, "Query must not be null!");
    Assert.notNull(update, "Update must not be null!");

    BulkWriteRequestBuilder builder = bulk.find(query.getQueryObject());

    if (upsert) {

        if (multi) {
            builder.upsert().update(update.getUpdateObject());
        } else {
            builder.upsert().updateOne(update.getUpdateObject());
        }

    } else {

        if (multi) {
            builder.update(update.getUpdateObject());
        } else {
            builder.updateOne(update.getUpdateObject());
        }
    }

    return this;
}