Packages

object Windows

Builders for windows used when expressing windowed computations. There are two types of windows: documents and range.

Bounded and half-bounded windows require sorting. Window bounds are inclusive and the lower bound must always be less than or equal to the upper bound. The following type-specific rules are applied to windows:

  • documents
    • bounds
      • 0 refers to the current document and is functionally equivalent to CURRENT;
      • a negative value refers to documents preceding the current one;
      • a positive value refers to documents following the current one;
  • range
    • sortBy
      • must contain exactly one field;
      • must specify the ascending sort order;
      • the sortBy field must be of either a numeric BSON type (see the $isNumber aggregation pipeline stage) or the BSON Date type if time bounds are used;
    • bounds
      • if numeric, i.e., not com.mongodb.client.model.Windows.Bound, then the bound is calculated by adding the value to the value of the sortBy field in the current document;
      • if CURRENT, then the bound is determined by the current document and not the current value of the sortBy field;
      • time bounds require specifying a time unit and are added as per the $dateAdd/$dateSubtract aggregation pipeline stage specification.
Annotations
@Beta()
Since

4.3

Note

Requires MongoDB 5.0 or greater.

See also

WindowedComputation

$isNumber aggregation pipeline stage

BSON Date type

$dateAdd aggregation pipeline stage

$dateSubtract aggregation pipeline stage

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Windows
  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. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  6. def documents(lower: Bound, upper: Bound): Window

    Creates a documents window whose bounds are determined by a number of documents before and after the current document.

    Creates a documents window whose bounds are determined by a number of documents before and after the current document.

    lower

    A value based on which the lower bound of the window is calculated.

    upper

    A value based on which the upper bound of the window is calculated.

    returns

    The constructed documents window.

  7. def documents(lower: Int, upper: Bound): Window

    Creates a documents window whose bounds are determined by a number of documents before and after the current document.

    Creates a documents window whose bounds are determined by a number of documents before and after the current document.

    lower

    A value based on which the lower bound of the window is calculated.

    upper

    A value based on which the upper bound of the window is calculated.

    returns

    The constructed documents window.

  8. def documents(lower: Bound, upper: Int): Window

    Creates a documents window whose bounds are determined by a number of documents before and after the current document.

    Creates a documents window whose bounds are determined by a number of documents before and after the current document.

    lower

    A value based on which the lower bound of the window is calculated.

    upper

    A value based on which the upper bound of the window is calculated.

    returns

    The constructed documents window.

    Note

    Requires MongoDB 5.0 or greater.

  9. def documents(lower: Int, upper: Int): Window

    Creates a documents window whose bounds are determined by a number of documents before and after the current document.

    Creates a documents window whose bounds are determined by a number of documents before and after the current document.

    lower

    A value based on which the lower bound of the window is calculated.

    upper

    A value based on which the upper bound of the window is calculated.

    returns

    The constructed documents window.

  10. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  11. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  12. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  13. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  14. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  15. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  16. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  17. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  18. def of(window: Bson): Window

    Creates a window from Bson in situations when there is no builder method that better satisfies your needs.

    Creates a window from Bson in situations when there is no builder method that better satisfies your needs. This method cannot be used to validate the syntax.

    Example
    The following code creates two functionally identical windows, though they may not be equal.

    val pastWeek1: Window = Windows.timeRange(-1, MongoTimeUnit.WEEK, Windows.Bound.CURRENT)
    val pastWeek2: Window = Windows.of(
        Document("range" -> BsonArray(-1, "current"),
            "unit" -> BsonString("week")))
    window

    A Bson representing the required window.

    returns

    The constructed window.

  19. def range(lower: Decimal128, upper: Bound): Window

    Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of the sortBy field in the current document.

    Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of the sortBy field in the current document.

    lower

    A value based on which the lower bound of the window is calculated.

    upper

    A value based on which the upper bound of the window is calculated.

    returns

    The constructed range window.

  20. def range(lower: Double, upper: Bound): Window

    Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of the sortBy field in the current document.

    Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of the sortBy field in the current document.

    lower

    A value based on which the lower bound of the window is calculated.

    upper

    A value based on which the upper bound of the window is calculated.

    returns

    The constructed range window.

  21. def range(lower: Long, upper: Bound): Window

    Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of the sortBy field in the current document.

    Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of the sortBy field in the current document.

    lower

    A value based on which the lower bound of the window is calculated.

    upper

    A value based on which the upper bound of the window is calculated.

    returns

    The constructed range window.

  22. def range(lower: Bound, upper: Decimal128): Window

    Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of the sortBy field in the current document.

    Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of the sortBy field in the current document.

    lower

    A value based on which the lower bound of the window is calculated.

    upper

    A value based on which the upper bound of the window is calculated.

    returns

    The constructed range window.

  23. def range(lower: Bound, upper: Double): Window

    Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of the sortBy field in the current document.

    Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of the sortBy field in the current document.

    lower

    A value based on which the lower bound of the window is calculated.

    upper

    A value based on which the upper bound of the window is calculated.

    returns

    The constructed range window.

  24. def range(lower: Bound, upper: Long): Window

    Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of the sortBy field in the current document.

    Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of the sortBy field in the current document.

    lower

    A value based on which the lower bound of the window is calculated.

    upper

    A value based on which the upper bound of the window is calculated.

    returns

    The constructed range window.

  25. def range(lower: Decimal128, upper: Decimal128): Window

    Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of the sortBy field in the current document.

    Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of the sortBy field in the current document.

    lower

    A value based on which the lower bound of the window is calculated.

    upper

    A value based on which the upper bound of the window is calculated.

    returns

    The constructed range window.

  26. def range(lower: Double, upper: Double): Window

    Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of the sortBy field in the current document.

    Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of the sortBy field in the current document.

    lower

    A value based on which the lower bound of the window is calculated.

    upper

    A value based on which the upper bound of the window is calculated.

    returns

    The constructed range window.

  27. def range(lower: Long, upper: Long): Window

    Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of the sortBy field in the current document.

    Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of the sortBy field in the current document.

    lower

    A value based on which the lower bound of the window is calculated.

    upper

    A value based on which the upper bound of the window is calculated.

    returns

    The constructed range window.

  28. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  29. def timeRange(lower: Long, unit: MongoTimeUnit, upper: Bound): Window

    Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the BSON Date value of the sortBy field in the current document.

    Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the BSON Date value of the sortBy field in the current document.

    lower

    A value based on which the lower bound of the window is calculated.

    unit

    A time unit in which lower is specified.

    upper

    A value based on which the upper bound of the window is calculated.

    returns

    The constructed range window.

  30. def timeRange(lower: Bound, upper: Long, unit: MongoTimeUnit): Window

    Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the BSON Date value of the sortBy field in the current document.

    Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the BSON Date value of the sortBy field in the current document.

    lower

    A value based on which the lower bound of the window is calculated.

    upper

    A value based on which the upper bound of the window is calculated.

    unit

    A time unit in which upper is specified.

    returns

    The constructed range window.

  31. def timeRange(lower: Long, upper: Long, unit: MongoTimeUnit): Window

    Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the BSON Date value of the sortBy field in the current document.

    Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the BSON Date value of the sortBy field in the current document.

    lower

    A value based on which the lower bound of the window is calculated.

    upper

    A value based on which the upper bound of the window is calculated.

    unit

    A time unit in which lower and upper are specified.

    returns

    The constructed range window.

  32. def toString(): String
    Definition Classes
    AnyRef → Any
  33. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  34. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  35. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  36. object Bound

    Special values that may be used when specifying the bounds of a window.

    Special values that may be used when specifying the bounds of a window.

    Annotations
    @Beta()
    Since

    4.3

    Note

    Requires MongoDB 5.0 or greater.

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