Search in sources :

Example 16 with Update

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

the class ExecutableUpdateOperationSupportTests method findAndModify.

// DATAMONGO-1563
@Test
void findAndModify() {
    Optional<Person> result = template.update(Person.class).matching(queryHan()).apply(new Update().set("firstname", "Han")).findAndModify();
    assertThat(result).contains(han);
    assertThat(template.findOne(queryHan(), Person.class)).isNotEqualTo(han).hasFieldOrPropertyWithValue("firstname", "Han");
}
Also used : Update(org.springframework.data.mongodb.core.query.Update) Test(org.junit.jupiter.api.Test)

Example 17 with Update

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

the class ExecutableUpdateOperationSupportTests method updateAllMatchingCriteria.

// DATAMONGO-2416
@Test
void updateAllMatchingCriteria() {
    UpdateResult result = template.update(Person.class).matching(where("id").is(han.getId())).apply(new Update().set("firstname", "Han")).all();
    assertThat(result.getModifiedCount()).isEqualTo(1L);
    assertThat(result.getUpsertedId()).isNull();
}
Also used : Update(org.springframework.data.mongodb.core.query.Update) UpdateResult(com.mongodb.client.result.UpdateResult) Test(org.junit.jupiter.api.Test)

Example 18 with Update

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

the class ExecutableUpdateOperationSupportTests method updateFirst.

// DATAMONGO-1563
@Test
void updateFirst() {
    UpdateResult result = template.update(Person.class).apply(new Update().set("firstname", "Han")).first();
    assertThat(result.getModifiedCount()).isEqualTo(1L);
    assertThat(result.getUpsertedId()).isNull();
}
Also used : Update(org.springframework.data.mongodb.core.query.Update) UpdateResult(com.mongodb.client.result.UpdateResult) Test(org.junit.jupiter.api.Test)

Example 19 with Update

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

the class ExecutableUpdateOperationSupportTests method findAndModifyValue.

// DATAMONGO-1719
@Test
void findAndModifyValue() {
    Person result = template.update(Person.class).matching(queryHan()).apply(new Update().set("firstname", "Han")).findAndModifyValue();
    assertThat(result).isEqualTo(han);
    assertThat(template.findOne(queryHan(), Person.class)).isNotEqualTo(han).hasFieldOrPropertyWithValue("firstname", "Han");
}
Also used : Update(org.springframework.data.mongodb.core.query.Update) Test(org.junit.jupiter.api.Test)

Example 20 with Update

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

the class ExecutableUpdateOperationSupportTests method updateAllMatching.

// DATAMONGO-1563
@Test
void updateAllMatching() {
    UpdateResult result = template.update(Person.class).matching(queryHan()).apply(new Update().set("firstname", "Han")).all();
    assertThat(result.getModifiedCount()).isEqualTo(1L);
    assertThat(result.getUpsertedId()).isNull();
}
Also used : Update(org.springframework.data.mongodb.core.query.Update) UpdateResult(com.mongodb.client.result.UpdateResult) Test(org.junit.jupiter.api.Test)

Aggregations

Update (org.springframework.data.mongodb.core.query.Update)212 Test (org.junit.jupiter.api.Test)179 Document (org.bson.Document)117 Query (org.springframework.data.mongodb.core.query.Query)72 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)57 NearQuery (org.springframework.data.mongodb.core.query.NearQuery)23 Bson (org.bson.conversions.Bson)21 FindOneAndUpdateOptions (com.mongodb.client.model.FindOneAndUpdateOptions)15 UpdateResult (com.mongodb.client.result.UpdateResult)12 ObjectId (org.bson.types.ObjectId)12 List (java.util.List)8 ToString (lombok.ToString)8 AggregationUpdate (org.springframework.data.mongodb.core.aggregation.AggregationUpdate)8 Criteria (org.springframework.data.mongodb.core.query.Criteria)8 VersionedPerson (org.springframework.data.mongodb.core.MongoTemplateTests.VersionedPerson)7 StepVerifier (reactor.test.StepVerifier)7 BsonDocument (org.bson.BsonDocument)6 UpdateOptions (com.mongodb.client.model.UpdateOptions)5 ArrayList (java.util.ArrayList)5 Instant (java.time.Instant)4