Class ArrayExpressions


  • public final class ArrayExpressions
    extends Object
    Defines helper methods for the array expressions
    Since:
    2.0
    • Method Detail

      • array

        public static ArrayExpression array​(Expression... expressions)
        Creates an array of the given expressions. This "expression" isn't so much a mongodb expression as it is a convenience method for building pipeline definitions.
        Parameters:
        expressions - the expressions
        Returns:
        the new expression
      • filter

        public static ArrayFilterExpression filter​(Expression array,
                                                   Expression conditional)
        Selects a subset of the array to return an array with only the elements that match the filter condition.
        Parameters:
        array - the array to use
        conditional - the conditional to use for filtering
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $filter
      • in

        public static Expression in​(Expression search,
                                    Expression array)
        Returns a boolean indicating whether a specified value is in an array.
        Parameters:
        search - the expression to search for
        array - the array to use
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $in
      • indexOfArray

        public static Expression indexOfArray​(Expression array,
                                              Expression search)
        Searches an array for an occurrence of a specified value and returns the array index of the first occurernce. If the substring is not found, returns -1.
        Parameters:
        array - the array to use
        search - the expression to search for
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $indexOfArray
      • map

        public static MapExpression map​(Expression input,
                                        Expression in)
        Applies a subexpression to each element of an array and returns the array of resulting values in order. Accepts named parameters.
        Parameters:
        input - the array to use
        in - An expression that is applied to each element of the input array.
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $map
      • range

        public static RangeExpression range​(int start,
                                            int end)
        Outputs an array containing a sequence of integers according to user-defined inputs.
        Parameters:
        start - the starting value
        end - the ending value
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $range
      • reduce

        public static Expression reduce​(Expression input,
                                        Expression initial,
                                        Expression in)
        Applies an expression to each element in an array and combines them into a single value.
        Parameters:
        input - the array to use
        initial - The initial cumulative value set before in is applied to the first element of the input array.
        in - A valid expression that $reduce applies to each element in the input array in left-to-right order.
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $reduce
      • slice

        public static Expression slice​(Expression array,
                                       int size)
        Returns a subset of an array.
        Parameters:
        array - the array to use
        size - the number of elements to return
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $slice