-
Notifications
You must be signed in to change notification settings - Fork 1.7k
DOCS-8290 - Added manual page for bucket pipeline stage. #2778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
name: groupBy | ||
position: 1 | ||
type: expression | ||
description: | | ||
An :ref:`expression <aggregation-expressions>` to group documents | ||
by. To specify a :ref:`field path<agg-quick-ref-field-paths>`, | ||
prefix the field name with a dollar sign ``$`` and enclose it in | ||
quotes. | ||
|
||
Unless :pipeline:`$bucket` includes a ``default`` | ||
specification, each input document must resolve the | ||
``groupBy`` field path or expression to a value that falls | ||
within one of the ranges specified by the ``boundaries``. | ||
optional: false | ||
operation: bucket | ||
interface: pipeline | ||
arg_name: field | ||
--- | ||
name: boundaries | ||
position: 2 | ||
type: array | ||
description: | | ||
An array of values based on the ``groupBy`` expression that specify | ||
the boundaries for each bucket. Each adjacent pair of values acts | ||
as the inclusive lower boundary and the exclusive upper boundary | ||
for the bucket. You must specify at least two boundaries. | ||
|
||
The specified values must be in ascending order and all of the same | ||
:doc:`type </reference/bson-types>`. The exception is if the values | ||
are of mixed numeric types, such as: | ||
|
||
``[ 10, NumberLong(20), NumberInt(30) ]`` | ||
|
||
If the values are documents, they must be wrapped in the | ||
:expression:`$literal` operator. | ||
|
||
.. example:: | ||
|
||
An array of ``[ 0, 5, 10 ]`` creates two buckets: | ||
|
||
- [0, 5) with inclusive lower bound ``0`` and exclusive upper | ||
bound ``5``. | ||
|
||
- [5, 10) with inclusive lower bound ``5`` and exclusive upper | ||
bound ``10``. | ||
|
||
optional: false | ||
interface: pipeline | ||
operation: bucket | ||
arg_name: field | ||
--- | ||
name: default | ||
position: 3 | ||
type: literal | ||
description: | | ||
A literal that specifies the ``_id`` of an additional bucket that | ||
contains all documents whose ``groupBy`` expression result does not | ||
fall into a bucket specified by ``boundaries``. | ||
|
||
If unspecified, each input document must resolve the | ||
``groupBy`` expression to a value within one of the bucket ranges | ||
specified by ``boundaries`` or the operation throws an error. | ||
|
||
The ``default`` value cannot overlap with a bucket; i.e. must | ||
be less than the lowest ``boundaries`` value or greater than the | ||
highest ``boundaries`` value. | ||
|
||
The ``default`` value can be of a different | ||
:doc:`type </reference/bson-types>` than the entries in | ||
``boundaries``. | ||
optional: true | ||
interface: pipeline | ||
operation: bucket | ||
arg_name: field | ||
--- | ||
name: output | ||
position: 4 | ||
type: document | ||
description: | | ||
A document that specifies the fields to include in the output | ||
documents in addition to the ``_id`` field. To specify the field to | ||
include, you must use | ||
:ref:`accumulator expressions<agg-quick-reference-accumulators>`. | ||
|
||
.. code-block:: javascript | ||
|
||
<outputfield1>: { <accumulator>: <expression1> }, | ||
... | ||
<outputfieldN>: { <accumulator>: <expressionN> } | ||
|
||
The default ``count`` field is not included in the output document | ||
when ``output`` is specified. Explicitly specify the ``count`` | ||
expression as part of the output document to include it: | ||
|
||
.. code-block:: javascript | ||
|
||
output: { | ||
<outputField1>: { <accumulator>: <expression1> }, | ||
... | ||
"count": { $sum: 1 } | ||
} | ||
|
||
optional: true | ||
interface: pipeline | ||
operation: bucket | ||
arg_name: field | ||
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatives:
Categorizes incoming documents into groups, called buckets, based on a specified expression. Each bucket has a user-specified range of the expression's values.
Categorizes incoming documents into groups, called buckets, based on a specified expression and the boundaries of each bucket.
If one of these sounds better and is used instead, change the first sentence of bucket.txt as well.