Fix SetOperation.toValueOf rendering for field references.
Use single field reference instead of invalid multi field. See: #4933
This commit is contained in:
@@ -140,7 +140,7 @@ public class SetOperation extends DocumentEnhancingOperation {
|
||||
@Override
|
||||
public SetOperation toValueOf(Object value) {
|
||||
|
||||
valueMap.put(field, value instanceof String stringValue ? Fields.fields(stringValue) : value);
|
||||
valueMap.put(field, value instanceof String stringValue ? Fields.field(stringValue) : value);
|
||||
return FieldAppender.this.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ class AddFieldsOperationUnitTests {
|
||||
assertThat(fields.getField("does-not-exist")).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-4933
|
||||
@Test // GH-4933
|
||||
void rendersStringValueAsFieldReferenceCorrectly() {
|
||||
|
||||
AddFieldsOperation operation = AddFieldsOperation.builder().addField("name").withValueOf("value").build();
|
||||
@@ -143,7 +143,6 @@ class AddFieldsOperationUnitTests {
|
||||
.containsExactly(Document.parse("{\"$addFields\" : {\"totalHomework\":\"$home_work\"}}"));
|
||||
}
|
||||
|
||||
|
||||
private static AggregationOperationContext contextFor(@Nullable Class<?> type) {
|
||||
|
||||
if (type == null) {
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.List;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
|
||||
import org.springframework.data.mongodb.core.convert.NoOpDbRefResolver;
|
||||
import org.springframework.data.mongodb.core.convert.QueryMapper;
|
||||
@@ -106,6 +105,22 @@ class SetOperationUnitTests {
|
||||
.containsExactly(Document.parse("{\"$set\" : {\"totalHomework\": { \"$sum\" : \"$homework\" }}}"));
|
||||
}
|
||||
|
||||
@Test // GH-4933
|
||||
void rendersTargetFieldReferenceCorrectly() {
|
||||
|
||||
assertThat(
|
||||
SetOperation.builder().set("totalHomework").toValueOf("homework").toPipelineStages(contextFor(Scores.class)))
|
||||
.containsExactly(Document.parse("{\"$set\" : {\"totalHomework\": \"$homework\" }}"));
|
||||
}
|
||||
|
||||
@Test // GH-4933
|
||||
void rendersMappedTargetFieldReferenceCorrectly() {
|
||||
|
||||
assertThat(SetOperation.builder().set("totalHomework").toValueOf("homework")
|
||||
.toPipelineStages(contextFor(ScoresWithMappedField.class)))
|
||||
.containsExactly(Document.parse("{\"$set\" : {\"totalHomework\": \"$home_work\" }}"));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2331
|
||||
void exposesFieldsCorrectly() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user