Search in sources :

Example 96 with Update

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

the class UpdateMapperUnitTests method testUpdateShouldAllowMultiplePushEachForDifferentFields.

// DATAMONGO-812
@Test
void testUpdateShouldAllowMultiplePushEachForDifferentFields() {
    Update update = new Update().push("category").each("spring", "data").push("type").each("mongodb");
    Document mappedObject = mapper.getMappedObject(update.getUpdateObject(), context.getPersistentEntity(Object.class));
    Document push = getAsDocument(mappedObject, "$push");
    assertThat(getAsDocument(push, "category")).containsKey("$each");
    assertThat(getAsDocument(push, "type")).containsKey("$each");
}
Also used : Update(org.springframework.data.mongodb.core.query.Update) Document(org.bson.Document) Test(org.junit.jupiter.api.Test)

Example 97 with Update

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

the class UpdateMapperUnitTests method mappingShouldNotRetainTypeInformationForConcreteValues.

// DATAMONGO-1236
@Test
void mappingShouldNotRetainTypeInformationForConcreteValues() {
    Update update = new Update().set("concreteValue", new NestedDocument("shallan"));
    Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(), context.getPersistentEntity(EntityWithObject.class));
    assertThat(mappedUpdate).containsEntry("$set.concreteValue.name", "shallan");
    assertThat(mappedUpdate).doesNotContainKey("$set.concreteValue._class");
}
Also used : Update(org.springframework.data.mongodb.core.query.Update) Document(org.bson.Document) Test(org.junit.jupiter.api.Test)

Example 98 with Update

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

the class UpdateMapperUnitTests method updatePushEachWithSliceShouldRenderCorrectly.

// DATAMONGO-832
@Test
void updatePushEachWithSliceShouldRenderCorrectly() {
    Update update = new Update().push("key").slice(5).each(Arrays.asList("Arya", "Arry", "Weasel"));
    Document mappedObject = mapper.getMappedObject(update.getUpdateObject(), context.getPersistentEntity(Object.class));
    Document push = getAsDocument(mappedObject, "$push");
    Document key = getAsDocument(push, "key");
    assertThat(key).containsKey("$slice").containsEntry("$slice", 5);
    assertThat(key).containsKey("$each");
}
Also used : Update(org.springframework.data.mongodb.core.query.Update) Document(org.bson.Document) Test(org.junit.jupiter.api.Test)

Example 99 with Update

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

the class UpdateMapperUnitTests method mappingShouldAllowPositionParameterWithIdentifier.

// DATAMONGO-2215
@Test
void mappingShouldAllowPositionParameterWithIdentifier() {
    Update update = // 
    new Update().set("grades.$[element]", 10).filterArray(Criteria.where("element").gte(100));
    Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(), context.getPersistentEntity(EntityWithListOfIntegers.class));
    assertThat(mappedUpdate).isEqualTo(new Document("$set", new Document("grades.$[element]", 10)));
}
Also used : Update(org.springframework.data.mongodb.core.query.Update) Document(org.bson.Document) Test(org.junit.jupiter.api.Test)

Example 100 with Update

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

the class UpdateMapperUnitTests method pathShouldIdentifyPositionalParameterWithMoreThanOneDigit.

// DATAMONGO-1809
@Test
void pathShouldIdentifyPositionalParameterWithMoreThanOneDigit() {
    Document at2digitPosition = mapper.getMappedObject(new Update().addToSet("concreteInnerList.10.concreteTypeList", new SomeInterfaceImpl("szeth")).getUpdateObject(), context.getPersistentEntity(Outer.class));
    Document at3digitPosition = mapper.getMappedObject(new Update().addToSet("concreteInnerList.123.concreteTypeList", new SomeInterfaceImpl("lopen")).getUpdateObject(), context.getPersistentEntity(Outer.class));
    assertThat(at2digitPosition).isEqualTo(new Document("$addToSet", new Document("concreteInnerList.10.concreteTypeList", new Document("value", "szeth"))));
    assertThat(at3digitPosition).isEqualTo(new Document("$addToSet", new Document("concreteInnerList.123.concreteTypeList", new Document("value", "lopen"))));
}
Also used : Document(org.bson.Document) Update(org.springframework.data.mongodb.core.query.Update) 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