Example usage for com.mongodb BulkWriteRequestBuilder update

List of usage examples for com.mongodb BulkWriteRequestBuilder update

Introduction

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

Prototype

public void update(final DBObject update) 

Source Link

Document

Adds a request to update all documents in the collection that match 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 w  w w  .ja  va2 s.co m*/
 * @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;
}