object WindowOutputFields
Builders for window output fields used in the
Aggregates.setWindowFields pipeline stage
of an aggregation pipeline. Each windowed output field is a triple:
- A window function. Some functions require documents in a window to be sorted
(see
sortByinAggregates.setWindowFields). - An optional window, a.k.a. frame.
Specifying
Nonewindow is equivalent to specifying an unbounded window, i.e., a window with both ends specified as UNBOUNDED. Some window functions, e.g., WindowOutputFields.derivative, require an explicit unbounded window instead ofNone. - 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
- Alphabetic
- By Inheritance
- WindowOutputFields
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def addToSet[TExpression](path: String, expression: TExpression, window: Option[_ <: Window]): WindowOutputField
Builds a computation that adds the evaluation results of the
expressionover thewindowto a BSONArrayand excludes duplicates.Builds a computation that adds the evaluation results of the
expressionover thewindowto a BSONArrayand 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
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def avg[TExpression](path: String, expression: TExpression, window: Option[_ <: Window]): WindowOutputField
Builds a computation of the average of the evaluation results of the
expressionover thewindow.Builds a computation of the average of the evaluation results of the
expressionover thewindow.- TExpression
The expression type.
- path
The output field path.
- expression
The expression.
- window
The window.
- returns
The constructed windowed computation.
- See also
- def bottom[OutExpression](path: String, sortBy: Bson, outExpression: OutExpression, window: Option[_ <: Window]): WindowOutputField
Builds a computation of the evaluation result of the
outExpressionagainst the bottom document in thewindowsorted according to the providedsortByspecification.Builds a computation of the evaluation result of the
outExpressionagainst the bottom document in thewindowsorted according to the providedsortByspecification.- 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
- def bottomN[OutExpression, NExpression](path: String, sortBy: Bson, outExpression: OutExpression, nExpression: NExpression, window: Option[_ <: Window]): WindowOutputField
Builds a computation of a BSON
Arrayof evaluation results of theoutExpressionagainst the bottomNdocuments in thewindowsorted according to the providedsortByspecification, whereNis the positive integral value of thenExpression.Builds a computation of a BSON
Arrayof evaluation results of theoutExpressionagainst the bottomNdocuments in thewindowsorted according to the providedsortByspecification, whereNis the positive integral value of thenExpression.- 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
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @IntrinsicCandidate()
- def count(path: String, window: Option[_ <: Window]): WindowOutputField
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
- def covariancePop[TExpression](path: String, expression1: TExpression, expression2: TExpression, window: Option[_ <: Window]): WindowOutputField
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
- def covarianceSamp[TExpression](path: String, expression1: TExpression, expression2: TExpression, window: Option[_ <: Window]): WindowOutputField
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
- def denseRank(path: String): WindowOutputField
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
sortByfields 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 singlesortByfield 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
- def derivative[TExpression](path: String, expression: TExpression, window: Window): WindowOutputField
Builds a computation of the time derivative by subtracting the evaluation result of the
expressionagainst the last document and the first document in thewindowand dividing it by the difference in the values of thesortByfield of the respective documents.Builds a computation of the time derivative by subtracting the evaluation result of the
expressionagainst the last document and the first document in thewindowand dividing it by the difference in the values of thesortByfield of the respective documents. Other documents in thewindowhave 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
- def documentNumber(path: String): WindowOutputField
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
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def expMovingAvg[TExpression](path: String, expression: TExpression, alpha: Double): WindowOutputField
Builds a computation of the exponential moving average of the evaluation results of the
expressionover the half-bounded window[UNBOUNDED, CURRENT], withalpharepresenting the degree of weighting decrease.Builds a computation of the exponential moving average of the evaluation results of the
expressionover the half-bounded window[UNBOUNDED, CURRENT], withalpharepresenting 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
alphadiscounts older observations faster. Must belong to the interval (0, 1).- returns
The constructed windowed computation.
- See also
- def expMovingAvg[TExpression](path: String, expression: TExpression, n: Int): WindowOutputField
Builds a computation of the exponential moving average of the evaluation results of the
expressionover a window that includesn- 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
expressionover a window that includesn- 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
- def first[TExpression](path: String, expression: TExpression, window: Option[_ <: Window]): WindowOutputField
Builds a computation of the evaluation result of the
expressionagainst the first document in thewindow.Builds a computation of the evaluation result of the
expressionagainst the first document in thewindow.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
- def firstN[InExpression, NExpression](path: String, inExpression: InExpression, nExpression: NExpression, window: Option[_ <: Window]): WindowOutputField
Builds a computation of a BSON
Arrayof evaluation results of theinExpressionagainst the firstNdocuments in thewindow, whereNis the positive integral value of thenExpression.Builds a computation of a BSON
Arrayof evaluation results of theinExpressionagainst the firstNdocuments in thewindow, whereNis the positive integral value of thenExpression.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
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
- def integral[TExpression](path: String, expression: TExpression, window: Window): WindowOutputField
Builds a computation of the approximate integral of a function that maps values of the
sortByfield to evaluation results of theexpressionagainst the same document.Builds a computation of the approximate integral of a function that maps values of the
sortByfield to evaluation results of theexpressionagainst the same document. The limits of integration match thewindowbounds. 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
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def last[TExpression](path: String, expression: TExpression, window: Option[_ <: Window]): WindowOutputField
Builds a computation of the evaluation result of the
expressionagainst the last document in thewindow.Builds a computation of the evaluation result of the
expressionagainst the last document in thewindow.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
- def lastN[InExpression, NExpression](path: String, inExpression: InExpression, nExpression: NExpression, window: Option[_ <: Window]): WindowOutputField
Builds a computation of a BSON
Arrayof evaluation results of theinExpressionagainst the lastNdocuments in thewindow, whereNis the positive integral value of thenExpression.Builds a computation of a BSON
Arrayof evaluation results of theinExpressionagainst the lastNdocuments in thewindow, whereNis the positive integral value of thenExpression.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
- def linearFill[TExpression](path: String, expression: TExpression): WindowOutputField
Builds a computation of a value that is equal to the evaluation result of the
expressionwhen it is non-Null, or to the linear interpolation of surrounding evaluation results of theexpressionwhen the result is BSONNull.Builds a computation of a value that is equal to the evaluation result of the
expressionwhen it is non-Null, or to the linear interpolation of surrounding evaluation results of theexpressionwhen the result is BSONNull.Sorting is required.
- TExpression
The expression type.
- path
The output field path.
- expression
The expression.
- returns
The constructed windowed computation.
- See also
- def locf[TExpression](path: String, expression: TExpression): WindowOutputField
Builds a computation of the last observed non-
Nullevaluation result of theexpression.Builds a computation of the last observed non-
Nullevaluation result of theexpression.Sorting is required.
- TExpression
The expression type.
- path
The output field path.
- expression
The expression.
- returns
The constructed windowed computation.
- See also
- def max[TExpression](path: String, expression: TExpression, window: Option[_ <: Window]): WindowOutputField
Builds a computation of the highest of the evaluation results of the
expressionover thewindow.Builds a computation of the highest of the evaluation results of the
expressionover thewindow.- TExpression
The expression type.
- path
The output field path.
- expression
The expression.
- window
The window.
- returns
The constructed windowed computation.
- See also
- def maxN[InExpression, NExpression](path: String, inExpression: InExpression, nExpression: NExpression, window: Option[_ <: Window]): WindowOutputField
Builds a computation of a BSON
ArrayofNlargest evaluation results of theinExpressionover thewindow, whereNis the positive integral value of thenExpression.Builds a computation of a BSON
ArrayofNlargest evaluation results of theinExpressionover thewindow, whereNis the positive integral value of thenExpression.- 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
- def median[InExpression](path: String, inExpression: InExpression, method: QuantileMethod, window: Option[_ <: Window]): WindowOutputField
Builds a window output field representing the median value of the evaluation results of the
inExpressionover documents in the specifiedwindow.Builds a window output field representing the median value of the evaluation results of the
inExpressionover documents in the specifiedwindow.- InExpression
The input expression type.
- inExpression
The input expression.
- method
The method to be used for computing the median.
- window
The window.
- returns
The constructed windowed computation.
- Since
4.10
- Note
Requires MongoDB 7.0 or greater
- See also
- def min[TExpression](path: String, expression: TExpression, window: Option[_ <: Window]): WindowOutputField
Builds a computation of the lowest of the evaluation results of the
expressionover thewindow.Builds a computation of the lowest of the evaluation results of the
expressionover thewindow.- TExpression
The expression type.
- path
The output field path.
- expression
The expression.
- window
The window.
- returns
The constructed windowed computation.
- See also
- def minN[InExpression, NExpression](path: String, inExpression: InExpression, nExpression: NExpression, window: Option[_ <: Window]): WindowOutputField
Builds a computation of a BSON
ArrayofNsmallest evaluation results of theinExpressionover thewindow, whereNis the positive integral value of thenExpression.Builds a computation of a BSON
ArrayofNsmallest evaluation results of theinExpressionover thewindow, whereNis the positive integral value of thenExpression.- 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
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
- def of(WindowOutputField: BsonField): WindowOutputField
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: WindowOutputField = WindowOutputFields.sum("pastWeekExpenses", "$expenses", pastWeek) val pastWeekExpenses2: WindowOutputField = WindowOutputFields.of( BsonField("pastWeekExpenses", Document("$sum" -> "$expenses", "window" -> pastWeek.toBsonDocument)))
- WindowOutputField
A document field representing the required windowed computation.
- returns
The constructed windowed computation.
- def percentile[InExpression, PExpression](path: String, inExpression: InExpression, pExpression: PExpression, method: QuantileMethod, window: Option[_ <: Window]): WindowOutputField
Builds a window output field of percentiles of the evaluation results of the
inExpressionover documents in the specifiedwindow.Builds a window output field of percentiles of the evaluation results of the
inExpressionover documents in the specifiedwindow. ThepExpressionparameter represents an array of percentiles of interest, with each element being a numeric value between 0.0 and 1.0 (inclusive).- InExpression
The input expression type.
- PExpression
The percentile expression type.
- path
The output field path.
- inExpression
The input expression.
- pExpression
The expression representing the percentiles of interest.
- method
The method to be used for computing the percentiles.
- window
The window.
- returns
The constructed windowed computation.
- Since
4.10
- Note
Requires MongoDB 7.0 or greater
- See also
- def push[TExpression](path: String, expression: TExpression, window: Option[_ <: Window]): WindowOutputField
Builds a computation that adds the evaluation results of the
expressionover thewindowto a BSONArray.Builds a computation that adds the evaluation results of the
expressionover thewindowto a BSONArray. Order within the array is guaranteed ifsortByis specified.- TExpression
The expression type.
- path
The output field path.
- expression
The expression.
- window
The window.
- returns
The constructed windowed computation.
- See also
- def rank(path: String): WindowOutputField
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
sortByfields 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 singlesortByfield 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
- def shift[TExpression >: Null](path: String, expression: TExpression, defaultExpression: Option[TExpression], by: Int): WindowOutputField
Builds a computation of the evaluation result of the
expressionfor the document whose position is shifted by the given amount relative to the current document.Builds a computation of the evaluation result of the
expressionfor 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 thedefaultExpressionis used instead of theexpression.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 BSONNull. 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
- def stdDevPop[TExpression](path: String, expression: TExpression, window: Option[_ <: Window]): WindowOutputField
Builds a computation of the population standard deviation of the evaluation results of the
expressionover thewindow.Builds a computation of the population standard deviation of the evaluation results of the
expressionover thewindow.- TExpression
The expression type.
- path
The output field path.
- expression
The expression.
- window
The window.
- returns
The constructed windowed computation.
- See also
- def stdDevSamp[TExpression](path: String, expression: TExpression, window: Option[_ <: Window]): WindowOutputField
Builds a computation of the sample standard deviation of the evaluation results of the
expressionover thewindow.Builds a computation of the sample standard deviation of the evaluation results of the
expressionover thewindow.- TExpression
The expression type.
- path
The output field path.
- expression
The expression.
- window
The window.
- returns
The constructed windowed computation.
- See also
- def sum[TExpression](path: String, expression: TExpression, window: Option[_ <: Window]): WindowOutputField
Builds a computation of the sum of the evaluation results of the
expressionover thewindow.Builds a computation of the sum of the evaluation results of the
expressionover thewindow.- TExpression
The expression type.
- path
The output field path.
- expression
The expression.
- window
The window.
- returns
The constructed windowed computation.
- See also
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def timeDerivative[TExpression](path: String, expression: TExpression, window: Window, unit: MongoTimeUnit): WindowOutputField
Builds a computation of the time derivative by subtracting the evaluation result of the
expressionagainst the last document and the first document in thewindowand dividing it by the difference in the BSONDatevalues of thesortByfield of the respective documents.Builds a computation of the time derivative by subtracting the evaluation result of the
expressionagainst the last document and the first document in thewindowand dividing it by the difference in the BSONDatevalues of thesortByfield of the respective documents. Other documents in thewindowhave 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
- def timeIntegral[TExpression](path: String, expression: TExpression, window: Window, unit: MongoTimeUnit): WindowOutputField
Builds a computation of the approximate integral of a function that maps BSON
Datevalues of thesortByfield to evaluation results of theexpressionagainst the same document.Builds a computation of the approximate integral of a function that maps BSON
Datevalues of thesortByfield to evaluation results of theexpressionagainst the same document. The limits of integration match thewindowbounds. 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
- def toString(): String
- Definition Classes
- AnyRef → Any
- def top[OutExpression](path: String, sortBy: Bson, outExpression: OutExpression, window: Option[_ <: Window]): WindowOutputField
Builds a computation of the evaluation result of the
outExpressionagainst the top document in thewindowsorted according to the providedsortByspecification.Builds a computation of the evaluation result of the
outExpressionagainst the top document in thewindowsorted according to the providedsortByspecification.- 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
- def topN[OutExpression, NExpression](path: String, sortBy: Bson, outExpression: OutExpression, nExpression: NExpression, window: Option[_ <: Window]): WindowOutputField
Builds a computation of a BSON
Arrayof evaluation results of theoutExpressionagainst the topNdocuments in thewindowsorted according to the providedsortByspecification, whereNis the positive integral value of thenExpression.Builds a computation of a BSON
Arrayof evaluation results of theoutExpressionagainst the topNdocuments in thewindowsorted according to the providedsortByspecification, whereNis the positive integral value of thenExpression.- 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
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated
This is the documentation for the MongoDB Scala driver.
Driver structure
The mongodb scala driver.
To get started you need a MongoClient instance, either from a connection string or via a org.mongodb.scala.MongoClientSettings.
Notable packages include: