Packages

o

org.mongodb.scala.model

WindowedComputations

object WindowedComputations

Builders for windowed computations used in the $setWindowFields pipeline stage of an aggregation pipeline. Each windowed computation is a triple:

  • A window function. Some functions require documents in a window to be sorted (see sortBy in Aggregates.setWindowFields).
  • An optional window, a.k.a. frame. Specifying None window is equivalent to specifying an unbounded window, i.e., a window with both ends specified as UNBOUNDED. Some window functions, e.g., WindowedComputations.derivative, require an explicit unbounded window instead of None.
  • A path to an output field to be computed by the window function over the window.

A windowed computation is similar to an accumulator but does not result in folding documents constituting the window into a single document.

Since

4.3

Note

Requires MongoDB 5.0 or greater.

See also

Field paths

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. WindowedComputations
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def addToSet[TExpression](path: String, expression: TExpression, window: Option[_ <: Window]): WindowedComputation

    Builds a computation that adds the evaluation results of the expression over the window to a BSON Array and excludes duplicates.

    Builds a computation 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.

    TExpression

    The expression type.

    path

    The output field path.

    expression

    The expression.

    window

    The window.

    returns

    The constructed windowed computation.

    See also

    $addToSet

  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def avg[TExpression](path: String, expression: TExpression, window: Option[_ <: Window]): WindowedComputation

    Builds a computation of the average of the evaluation results of the expression over the window.

    Builds a computation of the average of the evaluation results of the expression over the window.

    TExpression

    The expression type.

    path

    The output field path.

    expression

    The expression.

    window

    The window.

    returns

    The constructed windowed computation.

    See also

    $avg

  7. def bottom[OutExpression](path: String, sortBy: Bson, outExpression: OutExpression, window: Option[_ <: Window]): WindowedComputation

    Builds a computation of the evaluation result of the outExpression against the bottom document in the window sorted according to the provided sortBy specification.

    Builds a computation of the evaluation result of the outExpression against the bottom document in the window sorted according to the provided sortBy specification.

    OutExpression

    The type of the input expression.

    path

    The output field path.

    sortBy

    The sort specification. The syntax is identical to the one expected by Aggregates.sort.

    outExpression

    The output expression.

    returns

    The constructed windowed computation.

    Since

    4.7

    Note

    Requires MongoDB 5.2 or greater

    See also

    $bottom

  8. def bottomN[OutExpression, NExpression](path: String, sortBy: Bson, outExpression: OutExpression, nExpression: NExpression, window: Option[_ <: Window]): WindowedComputation

    Builds a computation 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.

    Builds a computation 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.

    OutExpression

    The type of the input expression.

    NExpression

    The type of the limiting expression.

    path

    The output field path.

    sortBy

    The sort specification. The syntax is identical to the one expected by Aggregates.sort.

    outExpression

    The output expression.

    nExpression

    The expression limiting the number of produced values.

    returns

    The constructed windowed computation.

    Since

    4.7

    Note

    Requires MongoDB 5.2 or greater

    See also

    $bottomN

  9. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @IntrinsicCandidate()
  10. def count(path: String, window: Option[_ <: Window]): WindowedComputation

    Builds a computation of the number of documents in the window.

    Builds a computation of the number of documents in the window.

    path

    The output field path.

    window

    The window.

    returns

    The constructed windowed computation.

    See also

    $count

  11. def covariancePop[TExpression](path: String, expression1: TExpression, expression2: TExpression, window: Option[_ <: Window]): WindowedComputation

    Builds a computation of the population covariance between the evaluation results of the two expressions over the window.

    Builds a computation of the population covariance between the evaluation results of the two expressions over the window.

    TExpression

    The expression type.

    path

    The output field path.

    expression1

    The first expression.

    expression2

    The second expression.

    window

    The window.

    returns

    The constructed windowed computation.

    See also

    $covariancePop

  12. def covarianceSamp[TExpression](path: String, expression1: TExpression, expression2: TExpression, window: Option[_ <: Window]): WindowedComputation

    Builds a computation of the sample covariance between the evaluation results of the two expressions over the window.

    Builds a computation of the sample covariance between the evaluation results of the two expressions over the window.

    TExpression

    The expression type.

    path

    The output field path.

    expression1

    The first expression.

    expression2

    The second expression.

    window

    The window.

    returns

    The constructed windowed computation.

    See also

    $covarianceSamp

  13. def denseRank(path: String): WindowedComputation

    Builds a computation of the dense rank of each document in its partition.

    Builds a computation 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.

    path

    The output field path.

    returns

    The constructed windowed computation.

    See also

    $denseRank

  14. def derivative[TExpression](path: String, expression: TExpression, window: Window): WindowedComputation

    Builds a computation 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 computation 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.

    TExpression

    The expression type.

    path

    The output field path.

    expression

    The expression.

    window

    The window.

    returns

    The constructed windowed computation.

    See also

    $derivative

  15. def documentNumber(path: String): WindowedComputation

    Builds a computation of the order number of each document in its partition.

    Builds a computation of the order number of each document in its partition.

    Sorting is required.

    path

    The output field path.

    returns

    The constructed windowed computation.

    See also

    $documentNumber

  16. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  17. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  18. def expMovingAvg[TExpression](path: String, expression: TExpression, alpha: Double): WindowedComputation

    Builds a computation of the exponential moving average of the evaluation results of the expression over the half-bounded window [UNBOUNDED, CURRENT], with alpha representing the degree of weighting decrease.

    Builds a computation of the exponential moving average of the evaluation results of the expression over the half-bounded window [UNBOUNDED, CURRENT], with alpha representing the degree of weighting decrease.

    Sorting is required.

    TExpression

    The expression type.

    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 computation.

    See also

    $expMovingAvg

  19. def expMovingAvg[TExpression](path: String, expression: TExpression, n: Int): WindowedComputation

    Builds a computation 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.

    Builds a computation 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.

    TExpression

    The expression type.

    path

    The output field path.

    expression

    The expression.

    n

    Must be positive.

    returns

    The constructed windowed computation.

    See also

    $expMovingAvg

  20. def first[TExpression](path: String, expression: TExpression, window: Option[_ <: Window]): WindowedComputation

    Builds a computation of the evaluation result of the expression against the first document in the window.

    Builds a computation of the evaluation result of the expression against the first document in the window.

    Sorting is required.

    TExpression

    The expression type.

    path

    The output field path.

    expression

    The expression.

    window

    The window.

    returns

    The constructed windowed computation.

    See also

    $first

  21. def firstN[InExpression, NExpression](path: String, inExpression: InExpression, nExpression: NExpression, window: Option[_ <: Window]): WindowedComputation

    Builds a computation 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.

    Builds a computation 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.

    InExpression

    The type of the input expression.

    NExpression

    The type of the limiting expression.

    path

    The output field path.

    inExpression

    The input expression.

    nExpression

    The expression limiting the number of produced values.

    returns

    The constructed windowed computation.

    Since

    4.7

    Note

    Requires MongoDB 5.2 or greater

    See also

    $firstN

  22. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @IntrinsicCandidate()
  23. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @IntrinsicCandidate()
  24. def integral[TExpression](path: String, expression: TExpression, window: Window): WindowedComputation

    Builds a computation of the approximate integral of a function that maps values of the sortBy field to evaluation results of the expression against the same document.

    Builds a computation 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.

    TExpression

    The expression type.

    path

    The output field path.

    expression

    The expression.

    window

    The window.

    returns

    The constructed windowed computation.

    See also

    $integral

  25. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  26. def last[TExpression](path: String, expression: TExpression, window: Option[_ <: Window]): WindowedComputation

    Builds a computation of the evaluation result of the expression against the last document in the window.

    Builds a computation of the evaluation result of the expression against the last document in the window.

    Sorting is required.

    TExpression

    The expression type.

    path

    The output field path.

    expression

    The expression.

    window

    The window.

    returns

    The constructed windowed computation.

    See also

    $last

  27. def lastN[InExpression, NExpression](path: String, inExpression: InExpression, nExpression: NExpression, window: Option[_ <: Window]): WindowedComputation

    Builds a computation 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.

    Builds a computation 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.

    InExpression

    The type of the input expression.

    NExpression

    The type of the limiting expression.

    path

    The output field path.

    inExpression

    The input expression.

    nExpression

    The expression limiting the number of produced values.

    returns

    The constructed windowed computation.

    Since

    4.7

    Note

    Requires MongoDB 5.2 or greater

    See also

    $lastN

  28. def max[TExpression](path: String, expression: TExpression, window: Option[_ <: Window]): WindowedComputation

    Builds a computation of the highest of the evaluation results of the expression over the window.

    Builds a computation of the highest of the evaluation results of the expression over the window.

    TExpression

    The expression type.

    path

    The output field path.

    expression

    The expression.

    window

    The window.

    returns

    The constructed windowed computation.

    See also

    $max

  29. def maxN[InExpression, NExpression](path: String, inExpression: InExpression, nExpression: NExpression, window: Option[_ <: Window]): WindowedComputation

    Builds a computation 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.

    Builds a computation 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.

    InExpression

    The type of the input expression.

    NExpression

    The type of the limiting expression.

    path

    The output field path.

    inExpression

    The input expression.

    nExpression

    The expression limiting the number of produced values.

    returns

    The constructed windowed computation.

    Since

    4.7

    Note

    Requires MongoDB 5.2 or greater

    See also

    $maxN

  30. def min[TExpression](path: String, expression: TExpression, window: Option[_ <: Window]): WindowedComputation

    Builds a computation of the lowest of the evaluation results of the expression over the window.

    Builds a computation of the lowest of the evaluation results of the expression over the window.

    TExpression

    The expression type.

    path

    The output field path.

    expression

    The expression.

    window

    The window.

    returns

    The constructed windowed computation.

    See also

    $min

  31. def minN[InExpression, NExpression](path: String, inExpression: InExpression, nExpression: NExpression, window: Option[_ <: Window]): WindowedComputation

    Builds a computation 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.

    Builds a computation 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.

    InExpression

    The type of the input expression.

    NExpression

    The type of the limiting expression.

    path

    The output field path.

    inExpression

    The input expression.

    nExpression

    The expression limiting the number of produced values.

    returns

    The constructed windowed computation.

    Since

    4.7

    Note

    Requires MongoDB 5.2 or greater

    See also

    $minN

  32. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  33. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @IntrinsicCandidate()
  34. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @IntrinsicCandidate()
  35. def of(windowedComputation: BsonField): WindowedComputation

    Creates a windowed computation from a document field in situations when there is no builder method that better satisfies your needs.

    Creates a windowed computation 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.

    val pastWeek: Window = Windows.timeRange(-1, MongoTimeUnit.WEEK, Windows.Bound.CURRENT)
    val pastWeekExpenses1: WindowedComputation = WindowedComputations.sum("pastWeekExpenses", "$expenses", pastWeek)
    val pastWeekExpenses2: WindowedComputation = WindowedComputations.of(
        BsonField("pastWeekExpenses", Document("$sum" -> "$expenses",
            "window" -> pastWeek.toBsonDocument)))
    windowedComputation

    A document field representing the required windowed computation.

    returns

    The constructed windowed computation.

  36. def push[TExpression](path: String, expression: TExpression, window: Option[_ <: Window]): WindowedComputation

    Builds a computation that adds the evaluation results of the expression over the window to a BSON Array.

    Builds a computation 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.

    TExpression

    The expression type.

    path

    The output field path.

    expression

    The expression.

    window

    The window.

    returns

    The constructed windowed computation.

    See also

    $push

  37. def rank(path: String): WindowedComputation

    Builds a computation of the rank of each document in its partition.

    Builds a computation 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.

    path

    The output field path.

    returns

    The constructed windowed computation.

    See also

    $rank

  38. def shift[TExpression >: Null](path: String, expression: TExpression, defaultExpression: Option[TExpression], by: Int): WindowedComputation

    Builds a computation of the evaluation result of the expression for the document whose position is shifted by the given amount relative to the current document.

    Builds a computation 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.

    TExpression

    The expression type.

    path

    The output field path.

    expression

    The expression.

    defaultExpression

    The default expression. If None, 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 computation.

    See also

    $shift

  39. def stdDevPop[TExpression](path: String, expression: TExpression, window: Option[_ <: Window]): WindowedComputation

    Builds a computation of the population standard deviation of the evaluation results of the expression over the window.

    Builds a computation of the population standard deviation of the evaluation results of the expression over the window.

    TExpression

    The expression type.

    path

    The output field path.

    expression

    The expression.

    window

    The window.

    returns

    The constructed windowed computation.

    See also

    $stdDevPop

  40. def stdDevSamp[TExpression](path: String, expression: TExpression, window: Option[_ <: Window]): WindowedComputation

    Builds a computation of the sample standard deviation of the evaluation results of the expression over the window.

    Builds a computation of the sample standard deviation of the evaluation results of the expression over the window.

    TExpression

    The expression type.

    path

    The output field path.

    expression

    The expression.

    window

    The window.

    returns

    The constructed windowed computation.

    See also

    $stdDevSamp

  41. def sum[TExpression](path: String, expression: TExpression, window: Option[_ <: Window]): WindowedComputation

    Builds a computation of the sum of the evaluation results of the expression over the window.

    Builds a computation of the sum of the evaluation results of the expression over the window.

    TExpression

    The expression type.

    path

    The output field path.

    expression

    The expression.

    window

    The window.

    returns

    The constructed windowed computation.

    See also

    $sum

  42. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  43. def timeDerivative[TExpression](path: String, expression: TExpression, window: Window, unit: MongoTimeUnit): WindowedComputation

    Builds a computation 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.

    Builds a computation 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.

    TExpression

    The expression type.

    path

    The output field path.

    expression

    The expression.

    window

    The window.

    unit

    The desired time unit for the divisor. Allowed values are: WEEK, DAY, HOUR, MINUTE, SECOND, MILLISECOND.

    returns

    The constructed windowed computation.

    See also

    $derivative

  44. def timeIntegral[TExpression](path: String, expression: TExpression, window: Window, unit: MongoTimeUnit): WindowedComputation

    Builds a computation 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.

    Builds a computation 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.

    TExpression

    The expression type.

    path

    The output field path.

    expression

    The expression.

    window

    The window.

    unit

    The desired time unit for the divisor. Allowed values are: WEEK, DAY, HOUR, MINUTE, SECOND, MILLISECOND.

    returns

    The constructed windowed computation.

    See also

    $integral

  45. def toString(): String
    Definition Classes
    AnyRef → Any
  46. def top[OutExpression](path: String, sortBy: Bson, outExpression: OutExpression, window: Option[_ <: Window]): WindowedComputation

    Builds a computation of the evaluation result of the outExpression against the top document in the window sorted according to the provided sortBy specification.

    Builds a computation of the evaluation result of the outExpression against the top document in the window sorted according to the provided sortBy specification.

    OutExpression

    The type of the input expression.

    path

    The output field path.

    sortBy

    The sort specification. The syntax is identical to the one expected by Aggregates.sort.

    outExpression

    The output expression.

    returns

    The constructed windowed computation.

    Since

    4.7

    Note

    Requires MongoDB 5.2 or greater

    See also

    $top

  47. def topN[OutExpression, NExpression](path: String, sortBy: Bson, outExpression: OutExpression, nExpression: NExpression, window: Option[_ <: Window]): WindowedComputation

    Builds a computation 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.

    Builds a computation 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.

    OutExpression

    The type of the input expression.

    NExpression

    The type of the limiting expression.

    path

    The output field path.

    sortBy

    The sort specification. The syntax is identical to the one expected by Aggregates.sort.

    outExpression

    The output expression.

    nExpression

    The expression limiting the number of produced values.

    returns

    The constructed windowed computation.

    Since

    4.7

    Note

    Requires MongoDB 5.2 or greater

    See also

    $topN

  48. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  49. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  50. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

Inherited from AnyRef

Inherited from Any

Ungrouped