File tree Expand file tree Collapse file tree 3 files changed +18
-4
lines changed
main/java/org/springframework/data/mongodb/core/aggregation
test/java/org/springframework/data/mongodb/core/aggregation Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ public SetOperation toValue(Object value) {
140140 @ Override
141141 public SetOperation toValueOf (Object value ) {
142142
143- valueMap .put (field , value instanceof String stringValue ? Fields .fields (stringValue ) : value );
143+ valueMap .put (field , value instanceof String stringValue ? Fields .field (stringValue ) : value );
144144 return FieldAppender .this .build ();
145145 }
146146
Original file line number Diff line number Diff line change @@ -128,7 +128,7 @@ void exposesFieldsCorrectly() {
128128 assertThat (fields .getField ("does-not-exist" )).isNull ();
129129 }
130130
131- @ Test // DATAMONGO -4933
131+ @ Test // GH -4933
132132 void rendersStringValueAsFieldReferenceCorrectly () {
133133
134134 AddFieldsOperation operation = AddFieldsOperation .builder ().addField ("name" ).withValueOf ("value" ).build ();
@@ -143,7 +143,6 @@ void rendersStringValueAsFieldReferenceCorrectly() {
143143 .containsExactly (Document .parse ("{\" $addFields\" : {\" totalHomework\" :\" $home_work\" }}" ));
144144 }
145145
146-
147146 private static AggregationOperationContext contextFor (@ Nullable Class <?> type ) {
148147
149148 if (type == null ) {
Original file line number Diff line number Diff line change 2121
2222import org .bson .Document ;
2323import org .junit .jupiter .api .Test ;
24-
2524import org .springframework .data .mongodb .core .convert .MappingMongoConverter ;
2625import org .springframework .data .mongodb .core .convert .NoOpDbRefResolver ;
2726import org .springframework .data .mongodb .core .convert .QueryMapper ;
@@ -106,6 +105,22 @@ void rendersTargetValueExpressionCorrectly() {
106105 .containsExactly (Document .parse ("{\" $set\" : {\" totalHomework\" : { \" $sum\" : \" $homework\" }}}" ));
107106 }
108107
108+ @ Test // GH-4933
109+ void rendersTargetFieldReferenceCorrectly () {
110+
111+ assertThat (
112+ SetOperation .builder ().set ("totalHomework" ).toValueOf ("homework" ).toPipelineStages (contextFor (Scores .class )))
113+ .containsExactly (Document .parse ("{\" $set\" : {\" totalHomework\" : \" $homework\" }}" ));
114+ }
115+
116+ @ Test // GH-4933
117+ void rendersMappedTargetFieldReferenceCorrectly () {
118+
119+ assertThat (SetOperation .builder ().set ("totalHomework" ).toValueOf ("homework" )
120+ .toPipelineStages (contextFor (ScoresWithMappedField .class )))
121+ .containsExactly (Document .parse ("{\" $set\" : {\" totalHomework\" : \" $home_work\" }}" ));
122+ }
123+
109124 @ Test // DATAMONGO-2331
110125 void exposesFieldsCorrectly () {
111126
You can’t perform that action at this time.
0 commit comments