For AI agents: a documentation index is available at https://www.mongodb.com/zh-cn/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

Window Functions

Window functions are used in $setWindowFields to return an aggregated value based on documents in a particular window.

Name
Description

Returns an array of all unique values from a particular window.

The order of the elements in the returned array is unspecified.

Returns the average of values from a particular window.

Returns the bottom element within a window according to the specified sort order.

Returns the bottom n elements within a particular window, according to the specified sort order.

Returns an array of the concatenated array values from documents in a window.

Returns the number of documents in a particular window.

Returns the value of an expression for the first document in a window.

Returns an array containing the first n elements within a window.

Returns the value of an expression for the last document in a window.

Returns an array containing the last n elements within a window.

Returns the maximum value from documents in a particular window.

Returns an array containing the maximum n elements within a window.

Returns the median (50th percentile) value from documents in a specified window. You can use $median in both document-based and range-based windows.

New in version 7.0.

Returns a document created by merging the input documents from a window.

Returns the minimum value from documents in a particular window.

Returns an array containing the n minimum values within a window.

Returns an array of percentile values for the specified percentiles within a window.

Returns an array of all values, including duplicates, that result from applying an expression to each document in a window.

Returns an array of the unique elements in the array values in a window.

New in version 8.1.

Returns the population standard deviation of values from documents in a particular window.

Returns the sample standard deviation of values in a window.

Returns the sum of numeric values from documents in a particular window.

Returns the top element within a window according to the specified sort order.

Returns the top n elements within a particular window, according to the specified sort order.

Rate this page