use of org.springframework.data.mongodb.core.aggregation.SetOperation in project spring-data-mongodb by spring-projects.
the class ReactiveMongoTemplateUnitTests method updateShouldPassOnUnsetCorrectly.
// DATAMONGO-2331
@Test
void updateShouldPassOnUnsetCorrectly() {
SetOperation setOperation = SetOperation.builder().set("status").toValue("Modified").and().set("comments").toValue(Fields.fields("misc1").and("misc2").asList());
AggregationUpdate update = AggregationUpdate.update();
update.set(setOperation);
update.unset("misc1", "misc2");
template.updateFirst(new BasicQuery("{}"), update, Wrapper.class).subscribe();
ArgumentCaptor<List<Document>> captor = ArgumentCaptor.forClass(List.class);
verify(collection, times(1)).updateOne(any(org.bson.Document.class), captor.capture(), any(UpdateOptions.class));
assertThat(captor.getValue()).isEqualTo(Arrays.asList(Document.parse("{ $set: { status: \"Modified\", comments: [ \"$misc1\", \"$misc2\" ] } }"), Document.parse("{ $unset: [ \"misc1\", \"misc2\" ] }")));
}
Aggregations