Package com.mongodb.client.model
Class Windows
java.lang.Object
com.mongodb.client.model.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
Windows.Bound.CURRENT; - a negative value refers to documents preceding the current one;
- a positive value refers to documents following the current one;
- 0 refers to the current document and is functionally equivalent to
- bounds
- range
sortBy- bounds
- if numeric, i.e., not
Windows.Bound, then the bound is calculated by adding the value to the value of thesortByfield in the current document; - if
Windows.Bound.CURRENT, then the bound is determined by the current document and not the current value of thesortByfield; - time bounds require specifying a time unit and are added as per the
$dateAdd/$dateSubtractaggregation pipeline stage specification.
- if numeric, i.e., not
- Since:
- 4.3
- See Also:
- MongoDB documentation
- $isNumber aggregation pipeline stage
- BSON Date type
- $dateAdd aggregation pipeline stage
- $dateSubtract aggregation pipeline stage
- Since server release
- 5.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumSpecial values that may be used when specifying the bounds of a window. -
Method Summary
Modifier and TypeMethodDescriptionstatic Windowdocuments(int lower, int upper) Creates a documents window whose bounds are determined by a number of documents before and after the current document.static Windowdocuments(int lower, Windows.Bound upper) Creates a documents window whose bounds are determined by a number of documents before and after the current document.static Windowdocuments(Windows.Bound lower, int upper) Creates a documents window whose bounds are determined by a number of documents before and after the current document.static Windowdocuments(Windows.Bound lower, Windows.Bound upper) Creates a documents window whose bounds are determined by a number of documents before and after the current document.static WindowCreates a window fromBsonin situations when there is no builder method that better satisfies your needs.static Windowrange(double lower, double upper) Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of thesortByfield in the current document.static Windowrange(double lower, Windows.Bound upper) Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of thesortByfield in the current document.static Windowrange(long lower, long upper) Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of thesortByfield in the current document.static Windowrange(long lower, Windows.Bound upper) Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of thesortByfield in the current document.static Windowrange(Windows.Bound lower, double upper) Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of thesortByfield in the current document.static Windowrange(Windows.Bound lower, long upper) Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of thesortByfield in the current document.static Windowrange(Windows.Bound lower, Decimal128 upper) Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of thesortByfield in the current document.static Windowrange(Decimal128 lower, Windows.Bound upper) Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of thesortByfield in the current document.static Windowrange(Decimal128 lower, Decimal128 upper) Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of thesortByfield in the current document.static WindowtimeRange(long lower, long upper, MongoTimeUnit unit) static WindowtimeRange(long lower, MongoTimeUnit unit, Windows.Bound upper) static WindowtimeRange(Windows.Bound lower, long upper, MongoTimeUnit unit)
-
Method Details
-
of
Creates a window fromBsonin 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 equivalent windows, though they may not be equal.Window pastWeek1 = Windows.timeRange(-1, MongoTimeUnit.WEEK, Windows.Bound.CURRENT); Window pastWeek2 = Windows.of( new Document("range", Arrays.asList(-1, "current")) .append("unit", MongoTimeUnit.WEEK.value()));- Parameters:
window- ABsonrepresenting the required window.- Returns:
- The constructed window.
-
documents
Creates a documents window whose bounds are determined by a number of documents before and after the current document.- Parameters:
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.
-
documents
Creates a documents window whose bounds are determined by a number of documents before and after the current document.- Parameters:
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.
-
documents
Creates a documents window whose bounds are determined by a number of documents before and after the current document.- Parameters:
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.
-
documents
Creates a documents window whose bounds are determined by a number of documents before and after the current document.- Parameters:
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.
-
range
Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of thesortByfield in the current document.- Parameters:
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.
-
range
Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of thesortByfield in the current document.- Parameters:
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.
-
range
Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of thesortByfield in the current document.- Parameters:
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.
-
range
Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of thesortByfield in the current document.- Parameters:
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.
-
range
Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of thesortByfield in the current document.- Parameters:
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.
-
range
Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of thesortByfield in the current document.- Parameters:
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.
-
range
Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of thesortByfield in the current document.- Parameters:
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.
-
range
Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of thesortByfield in the current document.- Parameters:
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.
-
range
Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the value of thesortByfield in the current document.- Parameters:
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.
-
timeRange
Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the BSONDatevalue of thesortByfield in the current document.- Parameters:
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 whichlowerandupperare specified.- Returns:
- The constructed range window.
-
timeRange
Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the BSONDatevalue of thesortByfield in the current document.- Parameters:
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 whichupperis specified.- Returns:
- The constructed range window.
-
timeRange
Creates a dynamically-sized range window whose bounds are determined by a range of possible values around the BSONDatevalue of thesortByfield in the current document.- Parameters:
lower- A value based on which the lower bound of the window is calculated.unit- A time unit in whichloweris specified.upper- A value based on which the upper bound of the window is calculated.- Returns:
- The constructed range window.
-