SetWindowFields class

$setWindowFields aggregation stage

Stage description

Available since MongoDB version 5.0

Performs operations on a specified span of documents in a collection, known as a window, and returns the results based on the chosen window operator.

For example, you can use the $setWindowFields stage to output the:

  • Difference in sales between two documents in a collection.
  • Sales rankings.
  • Cumulative sales totals.
  • Analysis of complex time series information without exporting the data to an external database.

Example:

Dart code:

  SetWindowFields(
     partitionBy: {r'$year': r"$orderDate"},
     sortBy: {'orderDate': 1},
     output: Output('cumulativeQuantityForYear', Sum(r'$quantity'),
         documents: ["unbounded", "current"])).build(),

Equivalent mongoDB aggregation stage:

 {
   r'$setWindowFields': {
     'partitionBy': {r'$year': r"$orderDate"},
     'sortBy': {'orderDate': 1},
     'output': {
       'cumulativeQuantityForYear': {
         r'$sum': r"$quantity",
         'window': {
           'documents': ["unbounded", "current"]
         }
       }
     }
   }
 }

https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/

Inheritance

Constructors

SetWindowFields({dynamic partitionBy, Map<String, int>? sortBy, dynamic defaultId, required dynamic output})
Creates $setWindowFields aggregation stage

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

build() Map<String, Object>
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited