29
29
import org .springframework .data .mongodb .core .aggregation .AggregationExpressions .Filter .AsBuilder ;
30
30
import org .springframework .data .mongodb .core .aggregation .AggregationExpressions .Let .ExpressionVariable ;
31
31
import org .springframework .data .mongodb .core .aggregation .ExposedFields .ExposedField ;
32
- import org .springframework .data .mongodb .core .aggregation .ExposedFields .FieldReference ;
33
32
import org .springframework .data .mongodb .core .query .CriteriaDefinition ;
34
33
import org .springframework .util .Assert ;
35
34
import org .springframework .util .ClassUtils ;
@@ -3903,31 +3902,19 @@ public static AsBuilder filter(List<?> values) {
3903
3902
*/
3904
3903
@ Override
3905
3904
public Document toDocument (final AggregationOperationContext context ) {
3906
-
3907
- return toFilter (new ExposedFieldsAggregationOperationContext (ExposedFields .from (as ), context ) {
3908
-
3909
- @ Override
3910
- public FieldReference getReference (Field field ) {
3911
-
3912
- FieldReference ref = null ;
3913
- try {
3914
- ref = context .getReference (field );
3915
- } catch (Exception e ) {
3916
- // just ignore that one.
3917
- }
3918
- return ref != null ? ref : super .getReference (field );
3919
- }
3920
- });
3905
+ return toFilter (ExposedFields .from (as ), context );
3921
3906
}
3922
3907
3923
- private Document toFilter (AggregationOperationContext context ) {
3908
+ private Document toFilter (ExposedFields exposedFields , AggregationOperationContext context ) {
3924
3909
3925
3910
Document filterExpression = new Document ();
3911
+ InheritingExposedFieldsAggregationOperationContext operationContext = new InheritingExposedFieldsAggregationOperationContext (
3912
+ exposedFields , context );
3926
3913
3927
3914
filterExpression .putAll (context .getMappedObject (new Document ("input" , getMappedInput (context ))));
3928
3915
filterExpression .put ("as" , as .getTarget ());
3929
3916
3930
- filterExpression .putAll (context .getMappedObject (new Document ("cond" , getMappedCondition (context ))));
3917
+ filterExpression .putAll (context .getMappedObject (new Document ("cond" , getMappedCondition (operationContext ))));
3931
3918
3932
3919
return new Document ("$filter" , filterExpression );
3933
3920
}
@@ -6017,27 +6004,14 @@ public Map andApply(final AggregationExpression expression) {
6017
6004
6018
6005
@ Override
6019
6006
public Document toDocument (final AggregationOperationContext context ) {
6020
-
6021
- return toMap (new ExposedFieldsAggregationOperationContext (
6022
- ExposedFields .synthetic (Fields .fields (itemVariableName )), context ) {
6023
-
6024
- @ Override
6025
- public FieldReference getReference (Field field ) {
6026
-
6027
- FieldReference ref = null ;
6028
- try {
6029
- ref = context .getReference (field );
6030
- } catch (Exception e ) {
6031
- // just ignore that one.
6032
- }
6033
- return ref != null ? ref : super .getReference (field );
6034
- }
6035
- });
6007
+ return toMap (ExposedFields .synthetic (Fields .fields (itemVariableName )), context );
6036
6008
}
6037
6009
6038
- private Document toMap (AggregationOperationContext context ) {
6010
+ private Document toMap (ExposedFields exposedFields , AggregationOperationContext context ) {
6039
6011
6040
6012
Document map = new Document ();
6013
+ InheritingExposedFieldsAggregationOperationContext operationContext = new InheritingExposedFieldsAggregationOperationContext (
6014
+ exposedFields , context );
6041
6015
6042
6016
Document input ;
6043
6017
if (sourceArray instanceof Field ) {
@@ -6048,7 +6022,8 @@ private Document toMap(AggregationOperationContext context) {
6048
6022
6049
6023
map .putAll (context .getMappedObject (input ));
6050
6024
map .put ("as" , itemVariableName );
6051
- map .put ("in" , functionToApply .toDocument (new NestedDelegatingExpressionAggregationOperationContext (context )));
6025
+ map .put ("in" ,
6026
+ functionToApply .toDocument (new NestedDelegatingExpressionAggregationOperationContext (operationContext )));
6052
6027
6053
6028
return new Document ("$map" , map );
6054
6029
}
@@ -6790,22 +6765,7 @@ public interface LetBuilder {
6790
6765
6791
6766
@ Override
6792
6767
public Document toDocument (final AggregationOperationContext context ) {
6793
-
6794
- return toLet (new ExposedFieldsAggregationOperationContext (
6795
- ExposedFields .synthetic (Fields .fields (getVariableNames ())), context ) {
6796
-
6797
- @ Override
6798
- public FieldReference getReference (Field field ) {
6799
-
6800
- FieldReference ref = null ;
6801
- try {
6802
- ref = context .getReference (field );
6803
- } catch (Exception e ) {
6804
- // just ignore that one.
6805
- }
6806
- return ref != null ? ref : super .getReference (field );
6807
- }
6808
- });
6768
+ return toLet (ExposedFields .synthetic (Fields .fields (getVariableNames ())), context );
6809
6769
}
6810
6770
6811
6771
private String [] getVariableNames () {
@@ -6814,20 +6774,24 @@ private String[] getVariableNames() {
6814
6774
for (int i = 0 ; i < this .vars .size (); i ++) {
6815
6775
varNames [i ] = this .vars .get (i ).variableName ;
6816
6776
}
6777
+
6817
6778
return varNames ;
6818
6779
}
6819
6780
6820
- private Document toLet (AggregationOperationContext context ) {
6781
+ private Document toLet (ExposedFields exposedFields , AggregationOperationContext context ) {
6821
6782
6822
6783
Document letExpression = new Document ();
6823
6784
6824
6785
Document mappedVars = new Document ();
6786
+ InheritingExposedFieldsAggregationOperationContext operationContext = new InheritingExposedFieldsAggregationOperationContext (
6787
+ exposedFields , context );
6788
+
6825
6789
for (ExpressionVariable var : this .vars ) {
6826
6790
mappedVars .putAll (getMappedVariable (var , context ));
6827
6791
}
6828
6792
6829
6793
letExpression .put ("vars" , mappedVars );
6830
- letExpression .put ("in" , getMappedIn (context ));
6794
+ letExpression .put ("in" , getMappedIn (operationContext ));
6831
6795
6832
6796
return new Document ("$let" , letExpression );
6833
6797
}
0 commit comments