Class AccumulatorExpressions


  • public final class AccumulatorExpressions
    extends Object
    Defines helper methods for accumulator expressions
    Since:
    2.0
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static dev.morphia.aggregation.expressions.impls.AccumulatorExpression accumulator​(String initFunction, String accumulateFunction, List<dev.morphia.aggregation.expressions.impls.Expression> accumulateArgs, String mergeFunction)
      Returns an array of unique expression values for each group.
      static dev.morphia.aggregation.expressions.impls.Expression addToSet​(dev.morphia.aggregation.expressions.impls.Expression value)
      Returns an array of unique expression values for each group.
      static dev.morphia.aggregation.expressions.impls.Expression avg​(dev.morphia.aggregation.expressions.impls.Expression value, dev.morphia.aggregation.expressions.impls.Expression... additional)
      Returns an average of numerical values.
      static dev.morphia.aggregation.expressions.impls.Expression bottom​(dev.morphia.aggregation.expressions.impls.Expression output, Sort... sortBy)
      Returns the bottom element within a group according to the specified sort order.
      static dev.morphia.aggregation.expressions.impls.Expression bottomN​(dev.morphia.aggregation.expressions.impls.Expression n, dev.morphia.aggregation.expressions.impls.Expression output, Sort... sortBy)
      Returns an aggregation of the bottom n elements within a group, according to the specified sort order.
      static dev.morphia.aggregation.expressions.impls.Expression first​(dev.morphia.aggregation.expressions.impls.Expression value)
      Returns a value from the first document for each group.
      static dev.morphia.aggregation.expressions.impls.Expression firstN​(dev.morphia.aggregation.expressions.impls.Expression n, dev.morphia.aggregation.expressions.impls.Expression input)
      Returns an aggregation of the first n elements within a group.
      static dev.morphia.aggregation.expressions.impls.Expression function​(String body, dev.morphia.aggregation.expressions.impls.Expression... args)
      Defines a custom aggregation function or expression in JavaScript.
      static dev.morphia.aggregation.expressions.impls.Expression last​(dev.morphia.aggregation.expressions.impls.Expression value)
      Returns a value from the last document for each group.
      static dev.morphia.aggregation.expressions.impls.Expression lastN​(dev.morphia.aggregation.expressions.impls.Expression n, dev.morphia.aggregation.expressions.impls.Expression input)
      Returns an aggregation of the last n elements within a group.
      static dev.morphia.aggregation.expressions.impls.Expression max​(dev.morphia.aggregation.expressions.impls.Expression value)
      Returns the highest expression value for each group.
      static dev.morphia.aggregation.expressions.impls.Expression maxN​(dev.morphia.aggregation.expressions.impls.Expression n, dev.morphia.aggregation.expressions.impls.Expression input)
      Returns an aggregation of the max n elements within a group.
      static dev.morphia.aggregation.expressions.impls.Expression min​(dev.morphia.aggregation.expressions.impls.Expression value)
      Returns the lowest expression value for each group.
      static dev.morphia.aggregation.expressions.impls.Expression minN​(dev.morphia.aggregation.expressions.impls.Expression n, dev.morphia.aggregation.expressions.impls.Expression input)
      Returns an aggregation of the min n elements within a group.
      static dev.morphia.aggregation.expressions.impls.Push push()
      Returns an array of all values that result from applying an expression to each document in a group of documents that share the same group by key.
      static dev.morphia.aggregation.expressions.impls.Expression push​(dev.morphia.aggregation.expressions.impls.Expression value)
      Returns an array of expression values for each group.
      static dev.morphia.aggregation.expressions.impls.Expression stdDevPop​(dev.morphia.aggregation.expressions.impls.Expression value, dev.morphia.aggregation.expressions.impls.Expression... additional)
      static dev.morphia.aggregation.expressions.impls.Expression stdDevSamp​(dev.morphia.aggregation.expressions.impls.Expression value, dev.morphia.aggregation.expressions.impls.Expression... additional)
      static dev.morphia.aggregation.expressions.impls.Expression sum​(dev.morphia.aggregation.expressions.impls.Expression first, dev.morphia.aggregation.expressions.impls.Expression... additional)
      Calculates and returns the sum of numeric values.
      static dev.morphia.aggregation.expressions.impls.Expression top​(dev.morphia.aggregation.expressions.impls.Expression output, Sort... sortBy)
      Returns the top element within a group according to the specified sort order.
      static dev.morphia.aggregation.expressions.impls.Expression topN​(dev.morphia.aggregation.expressions.impls.Expression n, dev.morphia.aggregation.expressions.impls.Expression output, Sort... sortBy)
      Returns an aggregation of the top n elements within a group, according to the specified sort order.
    • Method Detail

      • accumulator

        public static dev.morphia.aggregation.expressions.impls.AccumulatorExpression accumulator​(String initFunction,
                                                                                                  String accumulateFunction,
                                                                                                  List<dev.morphia.aggregation.expressions.impls.Expression> accumulateArgs,
                                                                                                  String mergeFunction)
        Returns an array of unique expression values for each group. Order of the array elements is undefined.
        Parameters:
        initFunction - used to initialize the state. The init function receives its arguments from the initArgs expression.
        accumulateFunction - used to accumulate documents. The accumulate function receives its arguments from the current state and accumulateArgs array expression.
        accumulateArgs - Arguments passed to the accumulate function.
        mergeFunction - used to merge two internal states.
        Returns:
        the new expression
        Since:
        2.1
        MongoDB documentation
        Aggregration Expression: $accumulator
      • addToSet

        public static dev.morphia.aggregation.expressions.impls.Expression addToSet​(dev.morphia.aggregation.expressions.impls.Expression value)
        Returns an array of unique expression values for each group. Order of the array elements is undefined.
        Parameters:
        value - the value
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $addToSet
      • avg

        public static dev.morphia.aggregation.expressions.impls.Expression avg​(dev.morphia.aggregation.expressions.impls.Expression value,
                                                                               dev.morphia.aggregation.expressions.impls.Expression... additional)
        Returns an average of numerical values. Ignores non-numeric values.
        Parameters:
        value - the value
        additional - any subsequent expressions to include in the expression
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $avg
      • bottom

        public static dev.morphia.aggregation.expressions.impls.Expression bottom​(dev.morphia.aggregation.expressions.impls.Expression output,
                                                                                  Sort... sortBy)
        Returns the bottom element within a group according to the specified sort order.
        Parameters:
        output - the expression listing the fields to use
        sortBy - the sort order
        Returns:
        the expression
        Since:
        2.3
        MongoDB documentation
        Aggregration Expression: $bottom
        Since server release
        5.2
      • bottomN

        public static dev.morphia.aggregation.expressions.impls.Expression bottomN​(dev.morphia.aggregation.expressions.impls.Expression n,
                                                                                   dev.morphia.aggregation.expressions.impls.Expression output,
                                                                                   Sort... sortBy)
        Returns an aggregation of the bottom n elements within a group, according to the specified sort order. If the group contains fewer than n elements, $bottomN returns all elements in the group.
        Parameters:
        n - the number of results per group and has to be a positive integral expression that is either a constant or depends on the _id value for $group
        output - the expression listing the fields to use
        sortBy - the sort order
        Returns:
        the expression
        Since:
        2.3
        MongoDB documentation
        Aggregration Expression: $bottomN
        Since server release
        5.2
      • first

        public static dev.morphia.aggregation.expressions.impls.Expression first​(dev.morphia.aggregation.expressions.impls.Expression value)
        Returns a value from the first document for each group. Order is only defined if the documents are in a defined order.
        Parameters:
        value - the value
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $first
      • firstN

        public static dev.morphia.aggregation.expressions.impls.Expression firstN​(dev.morphia.aggregation.expressions.impls.Expression n,
                                                                                  dev.morphia.aggregation.expressions.impls.Expression input)
        Returns an aggregation of the first n elements within a group. The elements returned are meaningful only if in a specified sort order. If the group contains fewer than n elements, $firstN returns all elements in the group.
        Parameters:
        n - the number of results per group and has to be a positive integral expression that is either a constant or depends on the _id value for $group
        input - the expression listing the fields to use
        Returns:
        the expression
        Since:
        2.3
        MongoDB documentation
        Aggregration Expression: $firstN
        Since server release
        5.2
      • function

        public static dev.morphia.aggregation.expressions.impls.Expression function​(String body,
                                                                                    dev.morphia.aggregation.expressions.impls.Expression... args)
        Defines a custom aggregation function or expression in JavaScript.
        Parameters:
        body - the function body
        args - the function arguments
        Returns:
        the new expression
        Since:
        2.1
        MongoDB documentation
        Aggregration Expression: $function
      • last

        public static dev.morphia.aggregation.expressions.impls.Expression last​(dev.morphia.aggregation.expressions.impls.Expression value)
        Returns a value from the last document for each group. Order is only defined if the documents are in a defined order.
        Parameters:
        value - the value
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $last
      • lastN

        public static dev.morphia.aggregation.expressions.impls.Expression lastN​(dev.morphia.aggregation.expressions.impls.Expression n,
                                                                                 dev.morphia.aggregation.expressions.impls.Expression input)
        Returns an aggregation of the last n elements within a group. The elements returned are meaningful only if in a specified sort order. If the group contains fewer than n elements, $lastN returns all elements in the group.
        Parameters:
        n - the number of results per group and has to be a positive integral expression that is either a constant or depends on the _id value for $group
        input - the expression listing the fields to use
        Returns:
        the expression
        Since:
        2.3
        MongoDB documentation
        Aggregration Expression: $lastN
        Since server release
        5.2
      • max

        public static dev.morphia.aggregation.expressions.impls.Expression max​(dev.morphia.aggregation.expressions.impls.Expression value)
        Returns the highest expression value for each group.
        Parameters:
        value - the value
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $max
      • maxN

        public static dev.morphia.aggregation.expressions.impls.Expression maxN​(dev.morphia.aggregation.expressions.impls.Expression n,
                                                                                dev.morphia.aggregation.expressions.impls.Expression input)
        Returns an aggregation of the max n elements within a group. The elements returned are meaningful only if in a specified sort order. If the group contains fewer than n elements, $maxN returns all elements in the group.
        Parameters:
        n - the number of results per group and n has to be a positive integral expression that is either a constant or depends on the _id value for $group.
        input - the expression that is the input to $maxN. It is evaluated for each element in the group and $maxN preserves the maximum n values.
        Returns:
        the expression
        Since:
        2.3
        MongoDB documentation
        Aggregration Expression: $maxN
        Since server release
        5.2
      • min

        public static dev.morphia.aggregation.expressions.impls.Expression min​(dev.morphia.aggregation.expressions.impls.Expression value)
        Returns the lowest expression value for each group.
        Parameters:
        value - the value
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $min
      • minN

        public static dev.morphia.aggregation.expressions.impls.Expression minN​(dev.morphia.aggregation.expressions.impls.Expression n,
                                                                                dev.morphia.aggregation.expressions.impls.Expression input)
        Returns an aggregation of the min n elements within a group. The elements returned are meaningful only if in a specified sort order. If the group contains fewer than n elements, $minN returns all elements in the group.
        Parameters:
        n - the number of results per group and n has to be a positive integral expression that is either a constant or depends on the _id value for $group.
        input - the expression that is the input to $minN. It is evaluated for each element in the group and $minN preserves the minimum n values.
        Returns:
        the expression
        Since:
        2.3
        MongoDB documentation
        Aggregration Expression: $minN
        Since server release
        5.2
      • push

        public static dev.morphia.aggregation.expressions.impls.Expression push​(dev.morphia.aggregation.expressions.impls.Expression value)
        Returns an array of expression values for each group.
        Parameters:
        value - the value
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $push
      • push

        public static dev.morphia.aggregation.expressions.impls.Push push()
        Returns an array of all values that result from applying an expression to each document in a group of documents that share the same group by key.

        $push is only available in the $group stage.

        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $push
      • sum

        public static dev.morphia.aggregation.expressions.impls.Expression sum​(dev.morphia.aggregation.expressions.impls.Expression first,
                                                                               dev.morphia.aggregation.expressions.impls.Expression... additional)
        Calculates and returns the sum of numeric values. $sum ignores non-numeric values.
        Parameters:
        first - the first expression to sum
        additional - any subsequent expressions to include in the sum
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $sum
      • top

        public static dev.morphia.aggregation.expressions.impls.Expression top​(dev.morphia.aggregation.expressions.impls.Expression output,
                                                                               Sort... sortBy)
        Returns the top element within a group according to the specified sort order.
        Parameters:
        output - the expression listing the fields to use
        sortBy - the sort order
        Returns:
        the expression
        Since:
        2.3
        MongoDB documentation
        Aggregration Expression: $top
        Since server release
        5.2
      • topN

        public static dev.morphia.aggregation.expressions.impls.Expression topN​(dev.morphia.aggregation.expressions.impls.Expression n,
                                                                                dev.morphia.aggregation.expressions.impls.Expression output,
                                                                                Sort... sortBy)
        Returns an aggregation of the top n elements within a group, according to the specified sort order. If the group contains fewer than n elements, $topN returns all elements in the group.
        Parameters:
        n - the number of results per group and has to be a positive integral expression that is either a constant or depends on the _id value for $group
        output - the expression listing the fields to use
        sortBy - the sort order
        Returns:
        the expression
        Since:
        2.3
        MongoDB documentation
        Aggregration Expression: $topN
        Since server release
        5.2
      • stdDevPop

        @Deprecated
        public static dev.morphia.aggregation.expressions.impls.Expression stdDevPop​(dev.morphia.aggregation.expressions.impls.Expression value,
                                                                                     dev.morphia.aggregation.expressions.impls.Expression... additional)
        Returns the population standard deviation of the input values.
        Parameters:
        value - the value
        additional - any subsequent expressions to include in the expression
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $stdDevPop
      • stdDevSamp

        @Deprecated
        public static dev.morphia.aggregation.expressions.impls.Expression stdDevSamp​(dev.morphia.aggregation.expressions.impls.Expression value,
                                                                                      dev.morphia.aggregation.expressions.impls.Expression... additional)
        Returns the sample standard deviation of the input values.
        Parameters:
        value - the value
        additional - any subsequent expressions to include in the expression
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $stdDevSamp