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
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) {
140
140
@ Override
141
141
public SetOperation toValueOf (Object value ) {
142
142
143
- valueMap .put (field , value instanceof String stringValue ? Fields .fields (stringValue ) : value );
143
+ valueMap .put (field , value instanceof String stringValue ? Fields .field (stringValue ) : value );
144
144
return FieldAppender .this .build ();
145
145
}
146
146
Original file line number Diff line number Diff line change @@ -128,7 +128,7 @@ void exposesFieldsCorrectly() {
128
128
assertThat (fields .getField ("does-not-exist" )).isNull ();
129
129
}
130
130
131
- @ Test // DATAMONGO -4933
131
+ @ Test // GH -4933
132
132
void rendersStringValueAsFieldReferenceCorrectly () {
133
133
134
134
AddFieldsOperation operation = AddFieldsOperation .builder ().addField ("name" ).withValueOf ("value" ).build ();
@@ -143,7 +143,6 @@ void rendersStringValueAsFieldReferenceCorrectly() {
143
143
.containsExactly (Document .parse ("{\" $addFields\" : {\" totalHomework\" :\" $home_work\" }}" ));
144
144
}
145
145
146
-
147
146
private static AggregationOperationContext contextFor (@ Nullable Class <?> type ) {
148
147
149
148
if (type == null ) {
Original file line number Diff line number Diff line change 21
21
22
22
import org .bson .Document ;
23
23
import org .junit .jupiter .api .Test ;
24
-
25
24
import org .springframework .data .mongodb .core .convert .MappingMongoConverter ;
26
25
import org .springframework .data .mongodb .core .convert .NoOpDbRefResolver ;
27
26
import org .springframework .data .mongodb .core .convert .QueryMapper ;
@@ -106,6 +105,22 @@ void rendersTargetValueExpressionCorrectly() {
106
105
.containsExactly (Document .parse ("{\" $set\" : {\" totalHomework\" : { \" $sum\" : \" $homework\" }}}" ));
107
106
}
108
107
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
+
109
124
@ Test // DATAMONGO-2331
110
125
void exposesFieldsCorrectly () {
111
126
You can’t perform that action at this time.
0 commit comments