use of com.mongodb.client.model.UpdateOptions in project mongo-java-driver by mongodb.
the class MongoCollectionImplTest method testUpdateMany.
@Test
public void testUpdateMany() {
UpdateOptions options = new UpdateOptions().collation(collation);
List<Document> updates = singletonList(new Document());
assertAll("updateMany", () -> assertAll("check validation", () -> assertThrows(IllegalArgumentException.class, () -> collection.updateMany(null, updates)), () -> assertThrows(IllegalArgumentException.class, () -> collection.updateMany(filter, (Bson) null)), () -> assertThrows(IllegalArgumentException.class, () -> collection.updateMany(clientSession, null, updates)), () -> assertThrows(IllegalArgumentException.class, () -> collection.updateMany(clientSession, filter, updates, null)), () -> assertThrows(IllegalArgumentException.class, () -> collection.updateMany(null, filter, updates)), () -> assertThrows(IllegalArgumentException.class, () -> collection.updateMany(null, filter, updates, options))), () -> {
Publisher<UpdateResult> expected = mongoOperationPublisher.updateMany(null, filter, updates, new UpdateOptions());
assertPublisherIsTheSameAs(expected, collection.updateMany(filter, updates), "Default");
}, () -> {
Publisher<UpdateResult> expected = mongoOperationPublisher.updateMany(null, filter, updates, options);
assertPublisherIsTheSameAs(expected, collection.updateMany(filter, updates, options), "With filter & options");
}, () -> {
Publisher<UpdateResult> expected = mongoOperationPublisher.updateMany(clientSession, filter, updates, new UpdateOptions());
assertPublisherIsTheSameAs(expected, collection.updateMany(clientSession, filter, updates), "With client session");
}, () -> {
Publisher<UpdateResult> expected = mongoOperationPublisher.updateMany(clientSession, filter, updates, options);
assertPublisherIsTheSameAs(expected, collection.updateMany(clientSession, filter, updates, options), "With client session, filter & options");
});
}
use of com.mongodb.client.model.UpdateOptions in project mongo-java-driver by mongodb.
the class MongoCollectionImplTest method testUpdateOne.
@Test
public void testUpdateOne() {
UpdateOptions options = new UpdateOptions().collation(collation);
Document update = new Document();
assertAll("updateOne", () -> assertAll("check validation", () -> assertThrows(IllegalArgumentException.class, () -> collection.updateOne(null, update)), () -> assertThrows(IllegalArgumentException.class, () -> collection.updateOne(filter, (Bson) null)), () -> assertThrows(IllegalArgumentException.class, () -> collection.updateOne(clientSession, null, update)), () -> assertThrows(IllegalArgumentException.class, () -> collection.updateOne(clientSession, filter, update, null)), () -> assertThrows(IllegalArgumentException.class, () -> collection.updateOne(null, filter, update)), () -> assertThrows(IllegalArgumentException.class, () -> collection.updateOne(null, filter, update, options))), () -> {
Publisher<UpdateResult> expected = mongoOperationPublisher.updateOne(null, filter, update, new UpdateOptions());
assertPublisherIsTheSameAs(expected, collection.updateOne(filter, update), "Default");
}, () -> {
Publisher<UpdateResult> expected = mongoOperationPublisher.updateOne(null, filter, update, options);
assertPublisherIsTheSameAs(expected, collection.updateOne(filter, update, options), "With filter & options");
}, () -> {
Publisher<UpdateResult> expected = mongoOperationPublisher.updateOne(clientSession, filter, update, new UpdateOptions());
assertPublisherIsTheSameAs(expected, collection.updateOne(clientSession, filter, update), "With client session");
}, () -> {
Publisher<UpdateResult> expected = mongoOperationPublisher.updateOne(clientSession, filter, update, options);
assertPublisherIsTheSameAs(expected, collection.updateOne(clientSession, filter, update, options), "With client session, filter & options");
});
}
use of com.mongodb.client.model.UpdateOptions in project java-design-patterns by iluwatar.
the class MongoBank method setFunds.
@Override
public void setFunds(String bankAccount, int amount) {
var search = new Document("_id", bankAccount);
var update = new Document("_id", bankAccount).append("funds", amount);
var updateOptions = new UpdateOptions().upsert(true);
accountsCollection.updateOne(search, new Document("$set", update), updateOptions);
}
use of com.mongodb.client.model.UpdateOptions in project spring-data-mongodb by spring-projects.
the class ReactiveMongoTemplateUnitTests method updateFirstShouldPreferExplicitCollationOverDefaultCollation.
// DATAMONGO-1854
@Test
void updateFirstShouldPreferExplicitCollationOverDefaultCollation() {
template.updateFirst(new BasicQuery("{}").collation(Collation.of("fr")), Update.update("foo", "bar"), Sith.class).subscribe();
ArgumentCaptor<UpdateOptions> options = ArgumentCaptor.forClass(UpdateOptions.class);
verify(collection).updateOne(any(), any(Bson.class), options.capture());
assertThat(options.getValue().getCollation()).isEqualTo(com.mongodb.client.model.Collation.builder().locale("fr").build());
}
use of com.mongodb.client.model.UpdateOptions in project spring-data-mongodb by spring-projects.
the class ReactiveMongoTemplateUnitTests method updateOneShouldUseCollationWhenPresent.
// DATAMONGO-1518
@Test
void updateOneShouldUseCollationWhenPresent() {
when(collection.updateOne(any(Bson.class), any(Bson.class), any())).thenReturn(Mono.empty());
template.updateFirst(new BasicQuery("{}").collation(Collation.of("fr")), new Update().set("foo", "bar"), AutogenerateableId.class).subscribe();
ArgumentCaptor<UpdateOptions> options = ArgumentCaptor.forClass(UpdateOptions.class);
verify(collection).updateOne(any(), any(Bson.class), options.capture());
assertThat(options.getValue().getCollation().getLocale()).isEqualTo("fr");
}
Aggregations