Class WindowOutputFields

java.lang.Object
com.mongodb.client.model.WindowOutputFields

public final class WindowOutputFields extends Object
Builders for window output fields used in the $setWindowFields pipeline stage of an aggregation pipeline. Each windowed computation is a triple: A window output field is similar to an accumulator but does not result in folding documents constituting the window into a single document.
Since:
4.3
MongoDB documentation
Field paths
Since server release
5.0
  • Method Summary

    Modifier and Type
    Method
    Description
    static <TExpression>
    WindowOutputField
    addToSet(String path, TExpression expression, Window window)
    Builds a window output field that adds the evaluation results of the expression over the window to a BSON Array and excludes duplicates.
    static <TExpression>
    WindowOutputField
    avg(String path, TExpression expression, Window window)
    Builds a window output field of the average of the evaluation results of the expression over the window.
    static <OutExpression>
    WindowOutputField
    bottom(String path, Bson sortBy, OutExpression outExpression, Window window)
    Builds a window output field of the evaluation result of the outExpression against the bottom document in the window sorted according to the provided sortBy specification.
    static <OutExpression, NExpression>
    WindowOutputField
    bottomN(String path, Bson sortBy, OutExpression outExpression, NExpression nExpression, Window window)
    Builds a window output field of a BSON Array of evaluation results of the outExpression against the bottom N documents in the window sorted according to the provided sortBy specification, where N is the positive integral value of the nExpression.
    count(String path, Window window)
    Builds a window output field of the number of documents in the window.
    static <TExpression>
    WindowOutputField
    covariancePop(String path, TExpression expression1, TExpression expression2, Window window)
    Builds a window output field of the population covariance between the evaluation results of the two expressions over the window.
    static <TExpression>
    WindowOutputField
    covarianceSamp(String path, TExpression expression1, TExpression expression2, Window window)
    Builds a window output field of the sample covariance between the evaluation results of the two expressions over the window.
    Builds a window output field of the dense rank of each document in its partition.
    static <TExpression>
    WindowOutputField
    derivative(String path, TExpression expression, Window window)
    Builds a window output field of the time derivative by subtracting the evaluation result of the expression against the last document and the first document in the window and dividing it by the difference in the values of the sortBy field of the respective documents.
    Builds a window output field of the order number of each document in its partition.
    static <TExpression>
    WindowOutputField
    expMovingAvg(String path, TExpression expression, double alpha)
    Builds a window output field of the exponential moving average of the evaluation results of the expression over the half-bounded window [Windows.Bound.UNBOUNDED, Windows.Bound.CURRENT], with alpha representing the degree of weighting decrease.
    static <TExpression>
    WindowOutputField
    expMovingAvg(String path, TExpression expression, int n)
    Builds a window output field of the exponential moving average of the evaluation results of the expression over a window that includes n - 1 documents preceding the current document and the current document, with more weight on documents closer to the current one.
    static <TExpression>
    WindowOutputField
    first(String path, TExpression expression, Window window)
    Builds a window output field of the evaluation result of the expression against the first document in the window.
    static <InExpression, NExpression>
    WindowOutputField
    firstN(String path, InExpression inExpression, NExpression nExpression, Window window)
    Builds a window output field of a BSON Array of evaluation results of the inExpression against the first N documents in the window, where N is the positive integral value of the nExpression.
    static <TExpression>
    WindowOutputField
    integral(String path, TExpression expression, Window window)
    Builds a window output field of the approximate integral of a function that maps values of the sortBy field to evaluation results of the expression against the same document.
    static <TExpression>
    WindowOutputField
    last(String path, TExpression expression, Window window)
    Builds a window output field of the evaluation result of the expression against the last document in the window.
    static <InExpression, NExpression>
    WindowOutputField
    lastN(String path, InExpression inExpression, NExpression nExpression, Window window)
    Builds a window output field of a BSON Array of evaluation results of the inExpression against the last N documents in the window, where N is the positive integral value of the nExpression.
    static <TExpression>
    WindowOutputField
    linearFill(String path, TExpression expression)
    Builds a window output field of a value that is equal to the evaluation result of the expression when it is non-Null, or to the linear interpolation of surrounding evaluation results of the expression when the result is Null.
    static <TExpression>
    WindowOutputField
    locf(String path, TExpression expression)
    Builds a window output field of the last observed non-Null evaluation result of the expression.
    static <TExpression>
    WindowOutputField
    max(String path, TExpression expression, Window window)
    Builds a window output field of the largest of the evaluation results of the expression over the window.
    static <InExpression, NExpression>
    WindowOutputField
    maxN(String path, InExpression inExpression, NExpression nExpression, Window window)
    Builds a window output field of a BSON Array of N largest evaluation results of the inExpression over the window, where N is the positive integral value of the nExpression.
    static <InExpression>
    WindowOutputField
    median(String path, InExpression inExpression, QuantileMethod method, Window window)
    Builds a window output field representing the median value of the evaluation results of the inExpression over documents in the specified window.
    static <TExpression>
    WindowOutputField
    min(String path, TExpression expression, Window window)
    Builds a window output field of the smallest of the evaluation results of the expression over the window.
    static <InExpression, NExpression>
    WindowOutputField
    minN(String path, InExpression inExpression, NExpression nExpression, Window window)
    Builds a window output field of a BSON Array of N smallest evaluation results of the inExpression over the window, where N is the positive integral value of the nExpression.
    of(BsonField windowOutputField)
    Creates a windowed output field from a document field in situations when there is no builder method that better satisfies your needs.
    static <InExpression, PExpression>
    WindowOutputField
    percentile(String path, InExpression inExpression, PExpression pExpression, QuantileMethod method, Window window)
    Builds a window output field of percentiles of the evaluation results of the inExpression over documents in the specified window.
    static <TExpression>
    WindowOutputField
    push(String path, TExpression expression, Window window)
    Builds a window output field that adds the evaluation results of the expression over the window to a BSON Array.
    rank(String path)
    Builds a window output field of the rank of each document in its partition.
    static <TExpression>
    WindowOutputField
    shift(String path, TExpression expression, TExpression defaultExpression, int by)
    Builds a window output field of the evaluation result of the expression for the document whose position is shifted by the given amount relative to the current document.
    static <TExpression>
    WindowOutputField
    stdDevPop(String path, TExpression expression, Window window)
    Builds a window output field of the population standard deviation of the evaluation results of the expression over the window.
    static <TExpression>
    WindowOutputField
    stdDevSamp(String path, TExpression expression, Window window)
    Builds a window output field of the sample standard deviation of the evaluation results of the expression over the window.
    static <TExpression>
    WindowOutputField
    sum(String path, TExpression expression, Window window)
    Builds a window output field of the sum of the evaluation results of the expression over the window.
    static <TExpression>
    WindowOutputField
    timeDerivative(String path, TExpression expression, Window window, MongoTimeUnit unit)
    Builds a window output field of the time derivative by subtracting the evaluation result of the expression against the last document and the first document in the window and dividing it by the difference in the BSON Date values of the sortBy field of the respective documents.
    static <TExpression>
    WindowOutputField
    timeIntegral(String path, TExpression expression, Window window, MongoTimeUnit unit)
    Builds a window output field of the approximate integral of a function that maps BSON Date values of the sortBy field to evaluation results of the expression against the same document.
    static <OutExpression>
    WindowOutputField
    top(String path, Bson sortBy, OutExpression outExpression, Window window)
    Builds a window output field of the evaluation result of the outExpression against the top document in the window sorted according to the provided sortBy specification.
    static <OutExpression, NExpression>
    WindowOutputField
    topN(String path, Bson sortBy, OutExpression outExpression, NExpression nExpression, Window window)
    Builds a window output field of a BSON Array of evaluation results of the outExpression against the top N documents in the window sorted according to the provided sortBy specification, where N is the positive integral value of the nExpression.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • of

      public static WindowOutputField of(BsonField windowOutputField)
      Creates a windowed output field from a document field in situations when there is no builder method that better satisfies your needs. This method cannot be used to validate the document field syntax.

      Example
      The following code creates two functionally equivalent window output fields, though they may not be equal.

      
        Window pastWeek = Windows.timeRange(-1, MongoTimeUnit.WEEK, Windows.Bound.CURRENT);
        WindowOutputField pastWeekExpenses1 = WindowOutputFields.sum("pastWeekExpenses", "$expenses", pastWeek);
        WindowOutputField pastWeekExpenses2 = WindowOutputFields.of(
                new BsonField("pastWeekExpenses", new Document("$sum", "$expenses")
                        .append("window", pastWeek.toBsonDocument())));
       
      Parameters:
      windowOutputField - A document field representing the required windowed output field.
      Returns:
      The constructed windowed output field.
    • sum

      public static <TExpression> WindowOutputField sum(String path, TExpression expression, @Nullable Window window)
      Builds a window output field of the sum of the evaluation results of the expression over the window.
      Type Parameters:
      TExpression - The expression type.
      Parameters:
      path - The output field path.
      expression - The expression.
      window - The window.
      Returns:
      The constructed windowed output field.
      MongoDB documentation
      $sum
    • avg

      public static <TExpression> WindowOutputField avg(String path, TExpression expression, @Nullable Window window)
      Builds a window output field of the average of the evaluation results of the expression over the window.
      Type Parameters:
      TExpression - The expression type.
      Parameters:
      path - The output field path.
      expression - The expression.
      window - The window.
      Returns:
      The constructed windowed output field.
      MongoDB documentation
      $avg
    • percentile

      public static <InExpression, PExpression> WindowOutputField percentile(String path, InExpression inExpression, PExpression pExpression, QuantileMethod method, @Nullable Window window)
      Builds a window output field of percentiles of the evaluation results of the inExpression over documents in the specified window. The pExpression parameter represents an array of percentiles of interest, with each element being a numeric value between 0.0 and 1.0 (inclusive).
      Type Parameters:
      InExpression - The type of the input expression.
      PExpression - The type of the percentile expression.
      Parameters:
      path - The output field path.
      inExpression - The input expression.
      pExpression - The expression representing a percentiles of interest.
      method - The method to be used for computing the percentiles.
      window - The window.
      Returns:
      The constructed windowed output field.
      Since:
      4.10
      MongoDB documentation
      $percentile
      Since server release
      7.0
    • median

      public static <InExpression> WindowOutputField median(String path, InExpression inExpression, QuantileMethod method, @Nullable Window window)
      Builds a window output field representing the median value of the evaluation results of the inExpression over documents in the specified window.
      Type Parameters:
      InExpression - The type of the input expression.
      Parameters:
      inExpression - The input expression.
      method - The method to be used for computing the median.
      window - The window.
      Returns:
      The constructed windowed output field.
      Since:
      4.10
      MongoDB documentation
      $median
      Since server release
      7.0
    • stdDevSamp

      public static <TExpression> WindowOutputField stdDevSamp(String path, TExpression expression, @Nullable Window window)
      Builds a window output field of the sample standard deviation of the evaluation results of the expression over the window.
      Type Parameters:
      TExpression - The expression type.
      Parameters:
      path - The output field path.
      expression - The expression.
      window - The window.
      Returns:
      The constructed windowed output field.
      MongoDB documentation
      $stdDevSamp
    • stdDevPop

      public static <TExpression> WindowOutputField stdDevPop(String path, TExpression expression, @Nullable Window window)
      Builds a window output field of the population standard deviation of the evaluation results of the expression over the window.
      Type Parameters:
      TExpression - The expression type.
      Parameters:
      path - The output field path.
      expression - The expression.
      window - The window.
      Returns:
      The constructed windowed output field.
      MongoDB documentation
      $stdDevPop
    • min

      public static <TExpression> WindowOutputField min(String path, TExpression expression, @Nullable Window window)
      Builds a window output field of the smallest of the evaluation results of the expression over the window.
      Type Parameters:
      TExpression - The expression type.
      Parameters:
      path - The output field path.
      expression - The expression.
      window - The window.
      Returns:
      The constructed windowed output field.
      MongoDB documentation
      $min
    • minN

      public static <InExpression, NExpression> WindowOutputField minN(String path, InExpression inExpression, NExpression nExpression, @Nullable Window window)
      Builds a window output field of a BSON Array of N smallest evaluation results of the inExpression over the window, where N is the positive integral value of the nExpression.
      Type Parameters:
      InExpression - The type of the input expression.
      NExpression - The type of the limiting expression.
      Parameters:
      path - The output field path.
      inExpression - The input expression.
      nExpression - The expression limiting the number of produced values.
      window - The window.
      Returns:
      The constructed windowed output field.
      Since:
      4.7
      MongoDB documentation
      $minN
      Since server release
      5.2
    • max

      public static <TExpression> WindowOutputField max(String path, TExpression expression, @Nullable Window window)
      Builds a window output field of the largest of the evaluation results of the expression over the window.
      Type Parameters:
      TExpression - The expression type.
      Parameters:
      path - The output field path.
      expression - The expression.
      window - The window.
      Returns:
      The constructed windowed output field.
      MongoDB documentation
      $max
    • maxN

      public static <InExpression, NExpression> WindowOutputField maxN(String path, InExpression inExpression, NExpression nExpression, @Nullable Window window)
      Builds a window output field of a BSON Array of N largest evaluation results of the inExpression over the window, where N is the positive integral value of the nExpression.
      Type Parameters:
      InExpression - The type of the input expression.
      NExpression - The type of the limiting expression.
      Parameters:
      path - The output field path.
      inExpression - The input expression.
      nExpression - The expression limiting the number of produced values.
      window - The window.
      Returns:
      The constructed windowed output field.
      Since:
      4.7
      MongoDB documentation
      $maxN
      Since server release
      5.2
    • count

      public static WindowOutputField count(String path, @Nullable Window window)
      Builds a window output field of the number of documents in the window.
      Parameters:
      path - The output field path.
      window - The window.
      Returns:
      The constructed windowed output field.
      MongoDB documentation
      $count
    • derivative

      public static <TExpression> WindowOutputField derivative(String path, TExpression expression, Window window)
      Builds a window output field of the time derivative by subtracting the evaluation result of the expression against the last document and the first document in the window and dividing it by the difference in the values of the sortBy field of the respective documents. Other documents in the window have no effect on the computation.

      Sorting is required.

      Type Parameters:
      TExpression - The expression type.
      Parameters:
      path - The output field path.
      expression - The expression.
      window - The window.
      Returns:
      The constructed windowed output field.
      MongoDB documentation
      $derivative
    • timeDerivative

      public static <TExpression> WindowOutputField timeDerivative(String path, TExpression expression, Window window, MongoTimeUnit unit)
      Builds a window output field of the time derivative by subtracting the evaluation result of the expression against the last document and the first document in the window and dividing it by the difference in the BSON Date values of the sortBy field of the respective documents. Other documents in the window have no effect on the computation.

      Sorting is required.

      Type Parameters:
      TExpression - The expression type.
      Parameters:
      path - The output field path.
      expression - The expression.
      window - The window.
      unit - The desired time unit for the divisor. Allowed values are: MongoTimeUnit.WEEK, MongoTimeUnit.DAY, MongoTimeUnit.HOUR, MongoTimeUnit.MINUTE, MongoTimeUnit.SECOND, MongoTimeUnit.MILLISECOND.
      Returns:
      The constructed windowed output field.
      MongoDB documentation
      $derivative
    • integral

      public static <TExpression> WindowOutputField integral(String path, TExpression expression, Window window)
      Builds a window output field of the approximate integral of a function that maps values of the sortBy field to evaluation results of the expression against the same document. The limits of integration match the window bounds. The approximation is done by using the trapezoidal rule.

      Sorting is required.

      Type Parameters:
      TExpression - The expression type.
      Parameters:
      path - The output field path.
      expression - The expression.
      window - The window.
      Returns:
      The constructed windowed output field.
      MongoDB documentation
      $integral
    • timeIntegral

      public static <TExpression> WindowOutputField timeIntegral(String path, TExpression expression, Window window, MongoTimeUnit unit)
      Builds a window output field of the approximate integral of a function that maps BSON Date values of the sortBy field to evaluation results of the expression against the same document. The limits of integration match the window bounds. The approximation is done by using the trapezoidal rule.

      Sorting is required.

      Type Parameters:
      TExpression - The expression type.
      Parameters:
      path - The output field path.
      expression - The expression.
      window - The window.
      unit - The desired time unit for the divisor. Allowed values are: MongoTimeUnit.WEEK, MongoTimeUnit.DAY, MongoTimeUnit.HOUR, MongoTimeUnit.MINUTE, MongoTimeUnit.SECOND, MongoTimeUnit.MILLISECOND.
      Returns:
      The constructed windowed output field.
      MongoDB documentation
      $integral
    • covarianceSamp

      public static <TExpression> WindowOutputField covarianceSamp(String path, TExpression expression1, TExpression expression2, @Nullable Window window)
      Builds a window output field of the sample covariance between the evaluation results of the two expressions over the window.
      Type Parameters:
      TExpression - The expression type.
      Parameters:
      path - The output field path.
      expression1 - The first expression.
      expression2 - The second expression.
      window - The window.
      Returns:
      The constructed windowed output field.
      MongoDB documentation
      $covarianceSamp
    • covariancePop

      public static <TExpression> WindowOutputField covariancePop(String path, TExpression expression1, TExpression expression2, @Nullable Window window)
      Builds a window output field of the population covariance between the evaluation results of the two expressions over the window.
      Type Parameters:
      TExpression - The expression type.
      Parameters:
      path - The output field path.
      expression1 - The first expression.
      expression2 - The second expression.
      window - The window.
      Returns:
      The constructed windowed output field.
      MongoDB documentation
      $covariancePop
    • expMovingAvg

      public static <TExpression> WindowOutputField expMovingAvg(String path, TExpression expression, int n)
      Builds a window output field of the exponential moving average of the evaluation results of the expression over a window that includes n - 1 documents preceding the current document and the current document, with more weight on documents closer to the current one.

      Sorting is required.

      Type Parameters:
      TExpression - The expression type.
      Parameters:
      path - The output field path.
      expression - The expression.
      n - Must be positive.
      Returns:
      The constructed windowed output field.
      MongoDB documentation
      $expMovingAvg
    • expMovingAvg

      public static <TExpression> WindowOutputField expMovingAvg(String path, TExpression expression, double alpha)
      Builds a window output field of the exponential moving average of the evaluation results of the expression over the half-bounded window [Windows.Bound.UNBOUNDED, Windows.Bound.CURRENT], with alpha representing the degree of weighting decrease.

      Sorting is required.

      Type Parameters:
      TExpression - The expression type.
      Parameters:
      path - The output field path.
      expression - The expression.
      alpha - A parameter specifying how fast weighting decrease happens. A higher alpha discounts older observations faster. Must belong to the interval (0, 1).
      Returns:
      The constructed windowed output field.
      MongoDB documentation
      $expMovingAvg
    • push

      public static <TExpression> WindowOutputField push(String path, TExpression expression, @Nullable Window window)
      Builds a window output field that adds the evaluation results of the expression over the window to a BSON Array. Order within the array is guaranteed if sortBy is specified.
      Type Parameters:
      TExpression - The expression type.
      Parameters:
      path - The output field path.
      expression - The expression.
      window - The window.
      Returns:
      The constructed windowed output field.
      MongoDB documentation
      $push
    • addToSet

      public static <TExpression> WindowOutputField addToSet(String path, TExpression expression, @Nullable Window window)
      Builds a window output field that adds the evaluation results of the expression over the window to a BSON Array and excludes duplicates. Order within the array is not specified.
      Type Parameters:
      TExpression - The expression type.
      Parameters:
      path - The output field path.
      expression - The expression.
      window - The window.
      Returns:
      The constructed windowed output field.
      MongoDB documentation
      $addToSet
    • first

      public static <TExpression> WindowOutputField first(String path, TExpression expression, @Nullable Window window)
      Builds a window output field of the evaluation result of the expression against the first document in the window.

      Sorting is required.

      Type Parameters:
      TExpression - The expression type.
      Parameters:
      path - The output field path.
      expression - The expression.
      window - The window.
      Returns:
      The constructed windowed output field.
      MongoDB documentation
      $first
    • firstN

      public static <InExpression, NExpression> WindowOutputField firstN(String path, InExpression inExpression, NExpression nExpression, @Nullable Window window)
      Builds a window output field of a BSON Array of evaluation results of the inExpression against the first N documents in the window, where N is the positive integral value of the nExpression.

      Sorting is required.

      Type Parameters:
      InExpression - The type of the input expression.
      NExpression - The type of the limiting expression.
      Parameters:
      path - The output field path.
      inExpression - The input expression.
      nExpression - The expression limiting the number of produced values.
      window - The window.
      Returns:
      The constructed windowed output field.
      Since:
      4.7
      MongoDB documentation
      $firstN
      Since server release
      5.2
    • top

      public static <OutExpression> WindowOutputField top(String path, Bson sortBy, OutExpression outExpression, @Nullable Window window)
      Builds a window output field of the evaluation result of the outExpression against the top document in the window sorted according to the provided sortBy specification.
      Type Parameters:
      OutExpression - The type of the output expression.
      Parameters:
      path - The output field path.
      sortBy - The sortBy specification. The syntax is identical to the one expected by Aggregates.sort(Bson).
      outExpression - The input expression.
      window - The window.
      Returns:
      The constructed windowed output field.
      Since:
      4.7
      MongoDB documentation
      $top
      Since server release
      5.2
    • topN

      public static <OutExpression, NExpression> WindowOutputField topN(String path, Bson sortBy, OutExpression outExpression, NExpression nExpression, @Nullable Window window)
      Builds a window output field of a BSON Array of evaluation results of the outExpression against the top N documents in the window sorted according to the provided sortBy specification, where N is the positive integral value of the nExpression.
      Type Parameters:
      OutExpression - The type of the output expression.
      NExpression - The type of the limiting expression.
      Parameters:
      path - The output field path.
      sortBy - The sortBy specification. The syntax is identical to the one expected by Aggregates.sort(Bson).
      outExpression - The input expression.
      nExpression - The expression limiting the number of produced values.
      window - The window.
      Returns:
      The constructed windowed output field.
      Since:
      4.7
      MongoDB documentation
      $topN
      Since server release
      5.2
    • last

      public static <TExpression> WindowOutputField last(String path, TExpression expression, @Nullable Window window)
      Builds a window output field of the evaluation result of the expression against the last document in the window.

      Sorting is required.

      Type Parameters:
      TExpression - The expression type.
      Parameters:
      path - The output field path.
      expression - The expression.
      window - The window.
      Returns:
      The constructed windowed output field.
      MongoDB documentation
      $last
    • lastN

      public static <InExpression, NExpression> WindowOutputField lastN(String path, InExpression inExpression, NExpression nExpression, @Nullable Window window)
      Builds a window output field of a BSON Array of evaluation results of the inExpression against the last N documents in the window, where N is the positive integral value of the nExpression.

      Sorting is required.

      Type Parameters:
      InExpression - The type of the input expression.
      NExpression - The type of the limiting expression.
      Parameters:
      path - The output field path.
      inExpression - The input expression.
      nExpression - The expression limiting the number of produced values.
      window - The window.
      Returns:
      The constructed windowed output field.
      Since:
      4.7
      MongoDB documentation
      $lastN
      Since server release
      5.2
    • bottom

      public static <OutExpression> WindowOutputField bottom(String path, Bson sortBy, OutExpression outExpression, @Nullable Window window)
      Builds a window output field of the evaluation result of the outExpression against the bottom document in the window sorted according to the provided sortBy specification.
      Type Parameters:
      OutExpression - The type of the output expression.
      Parameters:
      path - The output field path.
      sortBy - The sortBy specification. The syntax is identical to the one expected by Aggregates.sort(Bson).
      outExpression - The input expression.
      window - The window.
      Returns:
      The constructed windowed output field.
      Since:
      4.7
      MongoDB documentation
      $bottom
      Since server release
      5.2
    • bottomN

      public static <OutExpression, NExpression> WindowOutputField bottomN(String path, Bson sortBy, OutExpression outExpression, NExpression nExpression, @Nullable Window window)
      Builds a window output field of a BSON Array of evaluation results of the outExpression against the bottom N documents in the window sorted according to the provided sortBy specification, where N is the positive integral value of the nExpression.
      Type Parameters:
      OutExpression - The type of the output expression.
      NExpression - The type of the limiting expression.
      Parameters:
      path - The output field path.
      sortBy - The sortBy specification. The syntax is identical to the one expected by Aggregates.sort(Bson).
      outExpression - The input expression.
      nExpression - The expression limiting the number of produced values.
      window - The window.
      Returns:
      The constructed windowed output field.
      Since:
      4.7
      MongoDB documentation
      $bottomN
      Since server release
      5.2
    • shift

      public static <TExpression> WindowOutputField shift(String path, TExpression expression, @Nullable TExpression defaultExpression, int by)
      Builds a window output field of the evaluation result of the expression for the document whose position is shifted by the given amount relative to the current document. If the shifted document is outside of the partition containing the current document, then the defaultExpression is used instead of the expression.

      Sorting is required.

      Type Parameters:
      TExpression - The expression type.
      Parameters:
      path - The output field path.
      expression - The expression.
      defaultExpression - The default expression. If null, then the default expression is evaluated to BSON null. Must evaluate to a constant value.
      by - The shift specified similarly to rules for window bounds:
      • 0 means the current document;
      • a negative value refers to the document preceding the current one;
      • a positive value refers to the document following the current one.
      Returns:
      The constructed windowed output field.
      MongoDB documentation
      $shift
    • documentNumber

      public static WindowOutputField documentNumber(String path)
      Builds a window output field of the order number of each document in its partition.

      Sorting is required.

      Parameters:
      path - The output field path.
      Returns:
      The constructed windowed output field.
      MongoDB documentation
      $documentNumber
    • rank

      public static WindowOutputField rank(String path)
      Builds a window output field of the rank of each document in its partition. Documents with the same value(s) of the sortBy fields result in the same ranking and result in gaps in the returned ranks. For example, a partition with the sequence [1, 3, 3, 5] representing the values of the single sortBy field produces the following sequence of rank values: [1, 2, 2, 4].

      Sorting is required.

      Parameters:
      path - The output field path.
      Returns:
      The constructed windowed output field.
      MongoDB documentation
      $rank
    • denseRank

      public static WindowOutputField denseRank(String path)
      Builds a window output field of the dense rank of each document in its partition. Documents with the same value(s) of the sortBy fields result in the same ranking but do not result in gaps in the returned ranks. For example, a partition with the sequence [1, 3, 3, 5] representing the values of the single sortBy field produces the following sequence of rank values: [1, 2, 2, 3].

      Sorting is required.

      Parameters:
      path - The output field path.
      Returns:
      The constructed windowed output field.
      MongoDB documentation
      $denseRank
    • locf

      public static <TExpression> WindowOutputField locf(String path, TExpression expression)
      Builds a window output field of the last observed non-Null evaluation result of the expression.
      Type Parameters:
      TExpression - The expression type.
      Parameters:
      path - The output field path.
      expression - The expression.
      Returns:
      The constructed windowed output field.
      Since:
      4.7
      MongoDB documentation
      $locf
      Since server release
      5.2
    • linearFill

      public static <TExpression> WindowOutputField linearFill(String path, TExpression expression)
      Builds a window output field of a value that is equal to the evaluation result of the expression when it is non-Null, or to the linear interpolation of surrounding evaluation results of the expression when the result is Null.

      Sorting is required.

      Type Parameters:
      TExpression - The expression type.
      Parameters:
      path - The output field path.
      expression - The expression.
      Returns:
      The constructed windowed output field.
      Since:
      4.7
      MongoDB documentation
      $linearFill
      Since server release
      5.3