Search in sources :

Example 1 with ArrayFilter

use of org.springframework.data.mongodb.core.query.UpdateDefinition.ArrayFilter in project spring-data-mongodb by spring-projects.

the class DefaultBulkOperations method computeUpdateOptions.

/**
 * @param filterQuery The {@link Query} to read a potential {@link Collation} from. Must not be {@literal null}.
 * @param update The {@link Update} to apply
 * @param upsert flag to indicate if document should be upserted.
 * @return new instance of {@link UpdateOptions}.
 */
private static UpdateOptions computeUpdateOptions(Query filterQuery, UpdateDefinition update, boolean upsert) {
    UpdateOptions options = new UpdateOptions();
    options.upsert(upsert);
    if (update.hasArrayFilters()) {
        List<Document> list = new ArrayList<>(update.getArrayFilters().size());
        for (ArrayFilter arrayFilter : update.getArrayFilters()) {
            list.add(arrayFilter.asDocument());
        }
        options.arrayFilters(list);
    }
    filterQuery.getCollation().map(Collation::toMongoCollation).ifPresent(options::collation);
    return options;
}
Also used : ArrayFilter(org.springframework.data.mongodb.core.query.UpdateDefinition.ArrayFilter) ArrayList(java.util.ArrayList) Document(org.bson.Document)

Aggregations

ArrayList (java.util.ArrayList)1 Document (org.bson.Document)1 ArrayFilter (org.springframework.data.mongodb.core.query.UpdateDefinition.ArrayFilter)1