@Override com.mongodb.bulk.WriteRequest toNew(final DBCollection dbCollection) { return new com.mongodb.bulk.UpdateRequest(new BsonDocumentWrapper<DBObject>(query, codec), new BsonDocumentWrapper<DBObject>(document, replacementCodec), com.mongodb.bulk.WriteRequest.Type.REPLACE) .upsert(isUpsert()) .collation(getCollation()); } }
/** * Modify an existing document or documents in collection. * * @param query the selection criteria for the update * @param update the modifications to apply * @param options the options to apply to the update operation * @return the result of the operation * @throws com.mongodb.DuplicateKeyException if the write failed to a duplicate unique key * @throws com.mongodb.WriteConcernException if the write failed due some other failure specific to the update command * @throws MongoException if the operation failed for some other reason * @mongodb.driver.manual tutorial/modify-documents/ Modify * @since 3.4 */ public WriteResult update(final DBObject query, final DBObject update, final DBCollectionUpdateOptions options) { notNull("query", query); notNull("update", update); notNull("options", options); WriteConcern writeConcern = options.getWriteConcern() != null ? options.getWriteConcern() : getWriteConcern(); com.mongodb.bulk.WriteRequest.Type updateType = !update.keySet().isEmpty() && update.keySet().iterator().next().startsWith("$") ? com.mongodb.bulk.WriteRequest.Type.UPDATE : com.mongodb.bulk.WriteRequest.Type.REPLACE; UpdateRequest updateRequest = new UpdateRequest(wrap(query), wrap(update, options.getEncoder()), updateType) .upsert(options.isUpsert()).multi(options.isMulti()) .collation(options.getCollation()) .arrayFilters(wrapAllowNull(options.getArrayFilters(), options.getEncoder())); return executeWriteOperation(new UpdateOperation(getNamespace(), true, writeConcern, retryWrites, singletonList(updateRequest)).bypassDocumentValidation(options.getBypassDocumentValidation())); }
@Override com.mongodb.bulk.WriteRequest toNew(final DBCollection dbCollection) { return new com.mongodb.bulk.UpdateRequest(new BsonDocumentWrapper<DBObject>(query, codec), new BsonDocumentWrapper<DBObject>(update, codec), com.mongodb.bulk.WriteRequest.Type.UPDATE) .upsert(isUpsert()) .multi(isMulti()) .collation(getCollation()) .arrayFilters(dbCollection.wrapAllowNull(arrayFilters, codec)); } }
WriteRequest.Type.REPLACE) .upsert(replaceOneModel.getReplaceOptions().isUpsert()) .collation(replaceOneModel.getReplaceOptions().getCollation()); } else if (writeModel instanceof UpdateOneModel) { UpdateOneModel<TDocument> updateOneModel = (UpdateOneModel<TDocument>) writeModel; .multi(false) .upsert(updateOneModel.getOptions().isUpsert()) .collation(updateOneModel.getOptions().getCollation()) .arrayFilters(toBsonDocumentList(updateOneModel.getOptions().getArrayFilters())); } else if (writeModel instanceof UpdateManyModel) { .multi(true) .upsert(updateManyModel.getOptions().isUpsert()) .collation(updateManyModel.getOptions().getCollation()) .arrayFilters(toBsonDocumentList(updateManyModel.getOptions().getArrayFilters())); } else if (writeModel instanceof DeleteOneModel) {
@Override com.mongodb.bulk.WriteRequest toNew(final DBCollection dbCollection) { return new com.mongodb.bulk.UpdateRequest(new BsonDocumentWrapper<DBObject>(query, codec), new BsonDocumentWrapper<DBObject>(document, replacementCodec), com.mongodb.bulk.WriteRequest.Type.REPLACE) .upsert(isUpsert()) .collation(getCollation()); } }
@Override com.mongodb.bulk.WriteRequest toNew(final DBCollection dbCollection) { return new com.mongodb.bulk.UpdateRequest(new BsonDocumentWrapper<DBObject>(query, codec), new BsonDocumentWrapper<DBObject>(update, codec), com.mongodb.bulk.WriteRequest.Type.UPDATE) .upsert(isUpsert()) .multi(isMulti()) .collation(getCollation()) .arrayFilters(dbCollection.wrapAllowNull(arrayFilters, codec)); } }
/** * Modify an existing document or documents in collection. * * @param query the selection criteria for the update * @param update the modifications to apply * @param options the options to apply to the update operation * @return the result of the operation * @throws com.mongodb.DuplicateKeyException if the write failed to a duplicate unique key * @throws com.mongodb.WriteConcernException if the write failed due some other failure specific to the update command * @throws MongoException if the operation failed for some other reason * @mongodb.driver.manual tutorial/modify-documents/ Modify * @since 3.4 */ public WriteResult update(final DBObject query, final DBObject update, final DBCollectionUpdateOptions options) { notNull("query", query); notNull("update", update); notNull("options", options); WriteConcern writeConcern = options.getWriteConcern() != null ? options.getWriteConcern() : getWriteConcern(); com.mongodb.bulk.WriteRequest.Type updateType = !update.keySet().isEmpty() && update.keySet().iterator().next().startsWith("$") ? com.mongodb.bulk.WriteRequest.Type.UPDATE : com.mongodb.bulk.WriteRequest.Type.REPLACE; UpdateRequest updateRequest = new UpdateRequest(wrap(query), wrap(update, options.getEncoder()), updateType) .upsert(options.isUpsert()).multi(options.isMulti()) .collation(options.getCollation()) .arrayFilters(wrapAllowNull(options.getArrayFilters(), options.getEncoder())); return executeWriteOperation(new UpdateOperation(getNamespace(), true, writeConcern, retryWrites, singletonList(updateRequest)).bypassDocumentValidation(options.getBypassDocumentValidation())); }
WriteRequest.Type.REPLACE) .upsert(replaceOneModel.getReplaceOptions().isUpsert()) .collation(replaceOneModel.getReplaceOptions().getCollation()); } else if (writeModel instanceof UpdateOneModel) { UpdateOneModel<TDocument> updateOneModel = (UpdateOneModel<TDocument>) writeModel; .multi(false) .upsert(updateOneModel.getOptions().isUpsert()) .collation(updateOneModel.getOptions().getCollation()) .arrayFilters(toBsonDocumentList(updateOneModel.getOptions().getArrayFilters())); } else if (writeModel instanceof UpdateManyModel) { .multi(true) .upsert(updateManyModel.getOptions().isUpsert()) .collation(updateManyModel.getOptions().getCollation()) .arrayFilters(toBsonDocumentList(updateManyModel.getOptions().getArrayFilters())); } else if (writeModel instanceof DeleteOneModel) {