Search in sources :

Example 41 with UpdateOptions

use of com.mongodb.client.model.UpdateOptions in project spring-data-mongodb by spring-projects.

the class MongoTemplateUnitTests method updateMultiShouldUseDefaultCollationWhenPresent.

// DATAMONGO-1854
@Test
void updateMultiShouldUseDefaultCollationWhenPresent() {
    template.updateMulti(new BasicQuery("{}"), Update.update("foo", "bar"), Sith.class);
    ArgumentCaptor<UpdateOptions> options = ArgumentCaptor.forClass(UpdateOptions.class);
    verify(collection).updateMany(any(), any(Bson.class), options.capture());
    assertThat(options.getValue().getCollation()).isEqualTo(com.mongodb.client.model.Collation.builder().locale("de_AT").build());
}
Also used : BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) UpdateOptions(com.mongodb.client.model.UpdateOptions) FindOneAndUpdateOptions(com.mongodb.client.model.FindOneAndUpdateOptions) Bson(org.bson.conversions.Bson) Test(org.junit.jupiter.api.Test)

Example 42 with UpdateOptions

use of com.mongodb.client.model.UpdateOptions in project spring-data-mongodb by spring-projects.

the class ReactiveMongoTemplateUnitTests method updateMultiShouldPreferExplicitCollationOverDefaultCollation.

// DATAMONGO-1854
@Test
void updateMultiShouldPreferExplicitCollationOverDefaultCollation() {
    template.updateMulti(new BasicQuery("{}").collation(Collation.of("fr")), Update.update("foo", "bar"), Sith.class).subscribe();
    ArgumentCaptor<UpdateOptions> options = ArgumentCaptor.forClass(UpdateOptions.class);
    verify(collection).updateMany(any(), any(Bson.class), options.capture());
    assertThat(options.getValue().getCollation()).isEqualTo(com.mongodb.client.model.Collation.builder().locale("fr").build());
}
Also used : BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) UpdateOptions(com.mongodb.client.model.UpdateOptions) FindOneAndUpdateOptions(com.mongodb.client.model.FindOneAndUpdateOptions) Bson(org.bson.conversions.Bson) Test(org.junit.jupiter.api.Test)

Example 43 with UpdateOptions

use of com.mongodb.client.model.UpdateOptions in project spring-data-mongodb by spring-projects.

the class ReactiveMongoTemplateUnitTests method updateManyShouldUseCollationWhenPresent.

// DATAMONGO-1518
@Test
void updateManyShouldUseCollationWhenPresent() {
    when(collection.updateMany(any(Bson.class), any(Bson.class), any())).thenReturn(Mono.empty());
    template.updateMulti(new BasicQuery("{}").collation(Collation.of("fr")), new Update().set("foo", "bar"), AutogenerateableId.class).subscribe();
    ArgumentCaptor<UpdateOptions> options = ArgumentCaptor.forClass(UpdateOptions.class);
    verify(collection).updateMany(any(), any(Bson.class), options.capture());
    assertThat(options.getValue().getCollation().getLocale()).isEqualTo("fr");
}
Also used : BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) AutogenerateableId(org.springframework.data.mongodb.core.MongoTemplateUnitTests.AutogenerateableId) Update(org.springframework.data.mongodb.core.query.Update) AggregationUpdate(org.springframework.data.mongodb.core.aggregation.AggregationUpdate) UpdateOptions(com.mongodb.client.model.UpdateOptions) FindOneAndUpdateOptions(com.mongodb.client.model.FindOneAndUpdateOptions) Bson(org.bson.conversions.Bson) Test(org.junit.jupiter.api.Test)

Example 44 with UpdateOptions

use of com.mongodb.client.model.UpdateOptions in project spring-data-mongodb by spring-projects.

the class ReactiveMongoTemplateUnitTests method updateShouldApplyArrayFilters.

// DATAMONGO-2215
@Test
void updateShouldApplyArrayFilters() {
    template.updateFirst(new BasicQuery("{}"), new Update().set("grades.$[element]", 100).filterArray(Criteria.where("element").gte(100)), EntityWithListOfSimple.class).subscribe();
    ArgumentCaptor<UpdateOptions> options = ArgumentCaptor.forClass(UpdateOptions.class);
    verify(collection).updateOne(any(), any(Bson.class), options.capture());
    Assertions.assertThat((List<Bson>) options.getValue().getArrayFilters()).contains(new org.bson.Document("element", new Document("$gte", 100)));
}
Also used : Document(org.bson.Document) BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) List(java.util.List) ArrayList(java.util.ArrayList) Update(org.springframework.data.mongodb.core.query.Update) AggregationUpdate(org.springframework.data.mongodb.core.aggregation.AggregationUpdate) Document(org.bson.Document) UpdateOptions(com.mongodb.client.model.UpdateOptions) FindOneAndUpdateOptions(com.mongodb.client.model.FindOneAndUpdateOptions) Bson(org.bson.conversions.Bson) Test(org.junit.jupiter.api.Test)

Example 45 with UpdateOptions

use of com.mongodb.client.model.UpdateOptions in project spring-data-mongodb by spring-projects.

the class MongoTemplateUnitTests method updateFirstShouldUseDefaultCollationWhenPresent.

// DATAMONGO-1854
@Test
void updateFirstShouldUseDefaultCollationWhenPresent() {
    template.updateFirst(new BasicQuery("{}"), Update.update("foo", "bar"), Sith.class);
    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("de_AT").build());
}
Also used : BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) UpdateOptions(com.mongodb.client.model.UpdateOptions) FindOneAndUpdateOptions(com.mongodb.client.model.FindOneAndUpdateOptions) Bson(org.bson.conversions.Bson) Test(org.junit.jupiter.api.Test)

Aggregations

UpdateOptions (com.mongodb.client.model.UpdateOptions)53 Document (org.bson.Document)31 FindOneAndUpdateOptions (com.mongodb.client.model.FindOneAndUpdateOptions)21 Bson (org.bson.conversions.Bson)17 UpdateResult (com.mongodb.client.result.UpdateResult)10 Test (org.junit.jupiter.api.Test)10 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)8 ArrayList (java.util.ArrayList)6 BsonDocument (org.bson.BsonDocument)6 Test (org.junit.Test)6 Update (org.springframework.data.mongodb.core.query.Update)4 BasicDBObject (com.mongodb.BasicDBObject)3 MongoCollection (com.mongodb.client.MongoCollection)3 CountOptions (com.mongodb.client.model.CountOptions)3 IOException (java.io.IOException)3 List (java.util.List)3 BsonValue (org.bson.BsonValue)3 ObjectId (org.bson.types.ObjectId)3 MongodbException (com.duangframework.core.exceptions.MongodbException)2 Block (com.mongodb.Block)2