@ -24,6 +24,7 @@ import java.util.List;
import org.bson.Document ;
import org.bson.Document ;
import org.springframework.data.domain.Range ;
import org.springframework.data.domain.Range ;
import org.springframework.data.domain.Sort ;
import org.springframework.data.domain.Sort ;
import org.springframework.data.domain.Sort.Direction ;
import org.springframework.data.mongodb.core.aggregation.ArrayOperators.Filter.AsBuilder ;
import org.springframework.data.mongodb.core.aggregation.ArrayOperators.Filter.AsBuilder ;
import org.springframework.data.mongodb.core.aggregation.ArrayOperators.Reduce.PropertyExpression ;
import org.springframework.data.mongodb.core.aggregation.ArrayOperators.Reduce.PropertyExpression ;
import org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField ;
import org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField ;
@ -336,6 +337,22 @@ public class ArrayOperators {
return ( usesExpression ( ) ? SortArray . sortArrayOf ( expression ) : SortArray . sortArray ( values ) ) . by ( sort ) ;
return ( usesExpression ( ) ? SortArray . sortArrayOf ( expression ) : SortArray . sortArray ( values ) ) . by ( sort ) ;
}
}
/ * *
* Creates new { @link AggregationExpression } that takes the associated array and sorts it by the given { @link Sort
* order } .
*
* @return new instance of { @link SortArray } .
* @since 4 . 0
* /
public SortArray sort ( Direction direction ) {
if ( usesFieldRef ( ) ) {
return SortArray . sortArrayOf ( fieldReference ) . by ( direction ) ;
}
return ( usesExpression ( ) ? SortArray . sortArrayOf ( expression ) : SortArray . sortArray ( values ) ) . by ( direction ) ;
}
/ * *
/ * *
* Creates new { @link AggregationExpression } that transposes an array of input arrays so that the first element of
* Creates new { @link AggregationExpression } that transposes an array of input arrays so that the first element of
* the output array would be an array containing , the first element of the first input array , the first element of
* the output array would be an array containing , the first element of the first input array , the first element of
@ -2081,10 +2098,20 @@ public class ArrayOperators {
return new SortArray ( append ( "sortBy" , - 1 ) ) ;
return new SortArray ( append ( "sortBy" , - 1 ) ) ;
}
}
/ *
/ * *
* ( non - Javadoc )
* Set the order to put elements in .
* @see org . springframework . data . mongodb . core . aggregation . AbstractAggregationExpression # getMongoMethod ( )
*
* @param direction must not be { @literal null } .
* @return new instance of { @link SortArray } .
* /
* /
public SortArray by ( Direction direction ) {
return new SortArray ( append ( "sortBy" , direction . isAscending ( ) ? 1 : - 1 ) ) ;
}
/ *
* ( non - Javadoc )
* @see org . springframework . data . mongodb . core . aggregation . AbstractAggregationExpression # getMongoMethod ( )
* /
@Override
@Override
protected String getMongoMethod ( ) {
protected String getMongoMethod ( ) {
return "$sortArray" ;
return "$sortArray" ;