Class WindowExpressions


  • public final class WindowExpressions
    extends Object
    Provides window specific operations.
    Since:
    2.3
    • Method Detail

      • denseRank

        public static Expression denseRank()
        Returns the document position (known as the rank) relative to other documents in the $setWindowFields stage partition.
        Returns:
        the expression
        Since:
        2.3
        Since server release
        5.0
        MongoDB documentation
        Aggregration Expression: $denseRank
      • derivative

        public static CalculusExpression derivative​(Expression input)
        Returns the average rate of change within the specified window.
        Parameters:
        input - Specifies the expression to evaluate. The expression must evaluate to a number.
        Returns:
        the new expression
        Since:
        2.3
        Since server release
        5.0
        MongoDB documentation
        Aggregration Expression: $derivative
      • expMovingAvg

        public static Expression expMovingAvg​(Expression input,
                                              int n)
        Returns the exponential moving average of numeric expressions applied to documents in a partition defined in the $setWindowFields stage.

        $expMovingAvg is only available in the $setWindowFields stage.

        Parameters:
        input - Specifies the expression to evaluate. Non-numeric expressions are ignored.
        n - An integer that specifies the number of historical documents that have a significant mathematical weight in the exponential moving average calculation, with the most recent documents contributing the most weight.
        Returns:
        the new expression
        Since:
        2.3
        See Also:
        Aggregation.setWindowFields(SetWindowFields)
        Since server release
        5.0
        MongoDB documentation
        Aggregration Expression: $expMovingAvg
      • integral

        public static CalculusExpression integral​(Expression input)
        Returns the approximation of the area under a curve, which is calculated using the trapezoidal rule where each set of adjacent documents form a trapezoid using the:
        Parameters:
        input - Specifies the expression to evaluate. The expression must evaluate to a number.
        Returns:
        the new expression
        Since:
        2.3
        Since server release
        5.0
        MongoDB documentation
        Aggregration Expression: $integral
      • linearFill

        public static Expression linearFill​(Expression fillValue)
        Fills null and missing fields in a window using linear interpolation based on surrounding field values.

        $linearFill is only available in the $setWindowFields stage.

        Parameters:
        fillValue - the expression to use when calculating fill values
        Returns:
        the fill expression
        Since:
        2.3
        Since server release
        5.3
        MongoDB documentation
        Aggregration Expression: $linearFill
      • locf

        public static Expression locf​(Expression fillValue)
        Last observation carried forward. Set values for null and missing fields in a window to the last non-null value for the field.
        Parameters:
        fillValue - the expression to use when calculating fill values
        Returns:
        the fill expression
        Since:
        2.3
        Since server release
        5.2
        MongoDB documentation
        Aggregration Expression: $locf
      • rank

        public static Expression rank()
        Returns the document position (known as the rank) relative to other documents in the $setWindowFields stage partition.
        Returns:
        the new expression
        Since:
        2.3
        Since server release
        5.0
        MongoDB documentation
        Aggregration Expression: $rank
      • shift

        public static ShiftExpression shift​(Expression output,
                                            long by,
                                            Expression defaultValue)
        Returns the value from an expression applied to a document in a specified position relative to the current document in the $setWindowFields stage partition.
        Parameters:
        output - Specifies an expression to evaluate and return in the output.
        by - Specifies an integer with a numeric document position relative to the current document in the output.
        defaultValue - Specifies an optional default expression to evaluate if the document position is outside of the implicit $setWindowFields stage window. The implicit window contains all the documents in the partition.
        Returns:
        the expression
        Since:
        2.3
        See Also:
        Aggregation.setWindowFields(SetWindowFields)
        Since server release
        5.0
        MongoDB documentation
        Aggregration Expression: $shift
      • stdDevPop

        public static Expression stdDevPop​(Expression value,
                                           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
        Since:
        2.3
        MongoDB documentation
        Aggregration Expression: $stdDevPop
      • stdDevSamp

        public static Expression stdDevSamp​(Expression value,
                                            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
        Since:
        2.3
        MongoDB documentation
        Aggregration Expression: $stdDevSamp