Example usage for com.mongodb.client.model UpdateManyModel UpdateManyModel

List of usage examples for com.mongodb.client.model UpdateManyModel UpdateManyModel

Introduction

In this page you can find the example usage for com.mongodb.client.model UpdateManyModel UpdateManyModel.

Prototype

public UpdateManyModel(final Bson filter, final List<? extends Bson> update, final UpdateOptions options) 

Source Link

Document

Construct a new instance.

Usage

From source file:com.mastfrog.asyncpromises.mongo.BulkWriteBuilderImpl.java

License:Open Source License

public BulkWriteBuilder<T> updateMany(Bson filter, Bson update, UpdateOptions options) {
    requests.add(new UpdateManyModel<T>(filter, update, options));
    return this;
}

From source file:org.eclipse.ditto.services.thingsearch.persistence.write.impl.MongoThingsSearchUpdaterPersistence.java

License:Open Source License

@Override
public Source<List<Throwable>, NotUsed> purge(final CharSequence namespace) {
    final Bson filter = thingNamespaceFilter(namespace);
    final Bson update = new BsonDocument().append(AbstractWriteModel.SET,
            new BsonDocument().append(FIELD_DELETE_AT, new BsonDateTime(0L)));
    final UpdateOptions updateOptions = new UpdateOptions().bypassDocumentValidation(true);
    final WriteModel<Document> writeModel = new UpdateManyModel<>(filter, update, updateOptions);

    return Source.fromPublisher(collection.bulkWrite(Collections.singletonList(writeModel)))
            .map(bulkWriteResult -> Collections.<Throwable>emptyList())
            .recoverWithRetries(1, new PFBuilder<Throwable, Source<List<Throwable>, NotUsed>>()
                    .matchAny(throwable -> Source.single(Collections.singletonList(throwable))).build());
}

From source file:org.opencb.commons.datastore.mongodb.MongoDBNativeQuery.java

License:Apache License

public BulkWriteResult update(List<? extends Bson> documentList, List<? extends Bson> updatesList,
        boolean upsert, boolean multi) {
    if (documentList.size() != updatesList.size()) {
        throw wrongQueryUpdateSize(documentList, updatesList);
    }//  ww  w. j  av a2 s.  co  m

    Iterator<? extends Bson> queryIterator = documentList.iterator();
    Iterator<? extends Bson> updateIterator = updatesList.iterator();

    List<WriteModel<Document>> actions = new ArrayList<>(documentList.size());
    UpdateOptions updateOptions = new UpdateOptions().upsert(upsert);

    while (queryIterator.hasNext()) {
        Bson query = queryIterator.next();
        Bson update = updateIterator.next();

        if (multi) {
            actions.add(new UpdateManyModel<>(query, update, updateOptions));
        } else {
            actions.add(new UpdateOneModel<>(query, update, updateOptions));
        }

        //        BulkWriteOperation bulk = dbCollection.initializeUnorderedBulkOperation();
        //            BulkWriteRequestBuilder builder = bulk.find(query);
        //            if (upsert) {
        //                if (multi) {
        ////                    builder.upsert().update(update);
        //
        //                } else {
        ////                    builder.upsert().updateOne(update);
        //                }
        //            } else {
        //                if (multi) {
        ////                    builder.update(update);
        //                } else {
        ////                    builder.updateOne(update);
        //                }
        //            }

    }
    //        return bulk.execute();
    return dbCollection.bulkWrite(actions, new BulkWriteOptions().ordered(false));
}

From source file:org.restheart.db.DocumentDAO.java

License:Open Source License

@Override
public BulkOperationResult bulkPatchDocuments(String dbName, String collName, BsonDocument filter,
        BsonDocument shardedKeys, BsonDocument data) {
    MongoDatabase mdb = client.getDatabase(dbName);
    MongoCollection<BsonDocument> mcoll = mdb.getCollection(collName, BsonDocument.class);

    List<WriteModel<BsonDocument>> patches = new ArrayList<>();

    Bson _filter;//from   w  w w.  j  a v  a2 s.  com

    if (shardedKeys != null) {
        _filter = and(filter, shardedKeys);
    } else {
        _filter = filter;
    }

    patches.add(new UpdateManyModel<>(_filter, DAOUtils.getUpdateDocument(data), DAOUtils.U_NOT_UPSERT_OPS));

    BulkWriteResult result = mcoll.bulkWrite(patches);

    return new BulkOperationResult(HttpStatus.SC_OK, null, result);
}

From source file:org.wso2.extension.siddhi.store.mongodb.MongoDBEventTable.java

License:Open Source License

@Override
protected void updateOrAdd(CompiledCondition compiledCondition, List<Map<String, Object>> list,
        Map<String, CompiledExpression> map, List<Map<String, Object>> list1, List<Object[]> list2)
        throws ConnectionUnavailableException {
    List<UpdateManyModel<Document>> parsedRecords = list.stream().map(conditionParameterMap -> {
        int ordinal = list.indexOf(conditionParameterMap);
        Document updateFilter = MongoTableUtils.resolveCondition((MongoCompiledCondition) compiledCondition,
                conditionParameterMap);/*from   w ww  . j a  va2  s  .  c  om*/
        Document updateDocument = new Document().append("$set", list1.get(ordinal));
        UpdateOptions updateOptions = new UpdateOptions().upsert(true);
        return new UpdateManyModel<Document>(updateFilter, updateDocument, updateOptions);
    }).collect(Collectors.toList());
    this.bulkWrite(parsedRecords);
}