use of com.mongodb.client.model.DeleteOptions in project mongo-java-driver by mongodb.
the class CrudTest method getDeleteManyMongoOperation.
private MongoOperationDeleteResult getDeleteManyMongoOperation(final BsonDocument arguments) {
return new MongoOperationDeleteResult() {
@Override
public void execute() {
DeleteOptions options = new DeleteOptions();
if (arguments.containsKey("collation")) {
options.collation(getCollation(arguments.getDocument("collation")));
}
collection.deleteMany(arguments.getDocument("filter"), options, getCallback());
}
};
}
use of com.mongodb.client.model.DeleteOptions in project mongo-java-driver by mongodb.
the class CrudTest method getDeleteOneMongoOperation.
private MongoOperationDeleteResult getDeleteOneMongoOperation(final BsonDocument arguments) {
return new MongoOperationDeleteResult() {
@Override
public void execute() {
DeleteOptions options = new DeleteOptions();
if (arguments.containsKey("collation")) {
options.collation(getCollation(arguments.getDocument("collation")));
}
collection.deleteOne(arguments.getDocument("filter"), options, getCallback());
}
};
}
use of com.mongodb.client.model.DeleteOptions in project spring-data-mongodb by spring-projects.
the class ReactiveMongoTemplate method doRemove.
protected <T> Mono<DeleteResult> doRemove(String collectionName, Query query, @Nullable Class<T> entityClass) {
if (query == null) {
throw new InvalidDataAccessApiUsageException("Query passed in to remove can't be null!");
}
Assert.hasText(collectionName, "Collection name must not be null or empty!");
final Document queryObject = query.getQueryObject();
final MongoPersistentEntity<?> entity = getPersistentEntity(entityClass);
return execute(collectionName, collection -> {
Document removeQuey = queryMapper.getMappedObject(queryObject, entity);
maybeEmitEvent(new BeforeDeleteEvent<T>(removeQuey, entityClass, collectionName));
MongoAction mongoAction = new MongoAction(writeConcern, MongoActionOperation.REMOVE, collectionName, entityClass, null, removeQuey);
final DeleteOptions deleteOptions = new DeleteOptions();
query.getCollation().map(Collation::toMongoCollation).ifPresent(deleteOptions::collation);
WriteConcern writeConcernToUse = prepareWriteConcern(mongoAction);
MongoCollection<Document> collectionToUse = prepareCollection(collection, writeConcernToUse);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Remove using query: {} in collection: {}.", new Object[] { serializeToJsonSafely(removeQuey), collectionName });
}
if (query.getLimit() > 0 || query.getSkip() > 0) {
FindPublisher<Document> cursor = new QueryFindPublisherPreparer(query, entityClass).prepare(//
collection.find(removeQuey)).projection(new Document(ID_FIELD, 1));
return //
Flux.from(cursor).map(//
doc -> doc.get(ID_FIELD)).collectList().flatMapMany(val -> {
return collectionToUse.deleteMany(new Document(ID_FIELD, new Document("$in", val)), deleteOptions);
});
} else {
return collectionToUse.deleteMany(removeQuey, deleteOptions);
}
}).doOnNext(deleteResult -> maybeEmitEvent(new AfterDeleteEvent<T>(queryObject, entityClass, collectionName))).next();
}
use of com.mongodb.client.model.DeleteOptions in project spring-data-mongodb by spring-projects.
the class DefaultBulkOperations method remove.
/*
* (non-Javadoc)
* @see org.springframework.data.mongodb.core.BulkOperations#remove(org.springframework.data.mongodb.core.query.Query)
*/
@Override
public BulkOperations remove(Query query) {
Assert.notNull(query, "Query must not be null!");
DeleteOptions deleteOptions = new DeleteOptions();
query.getCollation().map(Collation::toMongoCollation).ifPresent(deleteOptions::collation);
models.add(new DeleteManyModel<>(query.getQueryObject(), deleteOptions));
return this;
}
use of com.mongodb.client.model.DeleteOptions in project spring-data-mongodb by spring-projects.
the class ReactiveMongoTemplateUnitTests method findAndRemoveManyShouldUseCollationWhenPresent.
// DATAMONGO-1518
@Test
public void findAndRemoveManyShouldUseCollationWhenPresent() {
when(collection.deleteMany(any(Bson.class), any())).thenReturn(Mono.empty());
template.doRemove("collection-1", new BasicQuery("{}").collation(Collation.of("fr")), AutogenerateableId.class).subscribe();
ArgumentCaptor<DeleteOptions> options = ArgumentCaptor.forClass(DeleteOptions.class);
verify(collection).deleteMany(Mockito.any(), options.capture());
assertThat(options.getValue().getCollation().getLocale(), is("fr"));
}
Aggregations