From 7732d098fdd314a9186da96ee96a87e3aa7b8112 Mon Sep 17 00:00:00 2001 From: Jason Price Date: Fri, 19 Mar 2021 12:23:33 -0700 Subject: [PATCH] DOCSP-10258 window functions --- source/reference/operator/aggregation.txt | 8 +- .../operator/aggregation/count-accum.txt | 89 ------------------- .../aggregation/count-accumulator.txt | 13 ++- .../reference/operator/aggregation/count.txt | 3 +- .../reference/operator/aggregation/first.txt | 3 +- .../operator/aggregation/integral.txt | 4 +- .../reference/operator/aggregation/last.txt | 3 +- source/release-notes/5.0.txt | 5 +- 8 files changed, 21 insertions(+), 107 deletions(-) delete mode 100644 source/reference/operator/aggregation/count-accum.txt diff --git a/source/reference/operator/aggregation.txt b/source/reference/operator/aggregation.txt index b1a4a33b7de..4eb4abfe772 100644 --- a/source/reference/operator/aggregation.txt +++ b/source/reference/operator/aggregation.txt @@ -1132,15 +1132,11 @@ Alphabetical Listing of Expression Operators /reference/operator/aggregation/convert /reference/operator/aggregation/cos /reference/operator/aggregation/cosh -<<<<<<< HEAD - /reference/operator/aggregation/count-accum - /reference/operator/aggregation/dateAdd - /reference/operator/aggregation/dateDiff -======= /reference/operator/aggregation/count-accumulator /reference/operator/aggregation/covariancePop /reference/operator/aggregation/covarianceSamp ->>>>>>> f7253052c... DOCSP-10258 window functions + /reference/operator/aggregation/dateAdd + /reference/operator/aggregation/dateDiff /reference/operator/aggregation/dateFromParts /reference/operator/aggregation/dateSubtract /reference/operator/aggregation/dateToParts diff --git a/source/reference/operator/aggregation/count-accum.txt b/source/reference/operator/aggregation/count-accum.txt deleted file mode 100644 index 6fad4423575..00000000000 --- a/source/reference/operator/aggregation/count-accum.txt +++ /dev/null @@ -1,89 +0,0 @@ -================================ -$count (aggregation accumulator) -================================ - -.. default-domain:: mongodb - -.. contents:: On this page - :local: - :backlinks: none - :depth: 1 - :class: singlecol - -Definition ----------- - -.. group:: $count - - .. versionadded:: 5.0 - - Returns the count of the documents in the stage. - - .. note:: Disambiguation - - The following page describes the accumulator :group:`$count`, - available only within the :pipeline:`$group` stage. For the - aggregation pipeline stage, see - :pipeline:`$count (aggregation stage) <$count>`. - -Syntax ------- - -:group:`$count` takes no arguments. :group:`$count` has the following -syntax: - -.. code-block:: javascript - - { $count: { } } - -Behavior --------- - -:group:`$count` is functionally equivalent to using ``{ $sum : 1 }`` -within the :pipeline:`$group` stage. - -.. seealso:: - - :group:`$sum` - - -Example -------- - -Consider a ``sales`` collection with the following documents: - -.. code-block:: javascript - - db.sales.insertMany([ - { "_id" : 1, "item" : "abc", "price" : 10, "quantity" : 2, "date" : ISODate("2021-01-01T08:00:00Z") }, - { "_id" : 2, "item" : "jkl", "price" : 20, "quantity" : 1, "date" : ISODate("2021-02-03T09:00:00Z") }, - { "_id" : 3, "item" : "xyz", "price" : 5, "quantity" : 5, "date" : ISODate("2021-02-03T09:05:00Z") }, - { "_id" : 4, "item" : "abc", "price" : 10, "quantity" : 10, "date" : ISODate("2021-02-15T08:00:00Z") }, - { "_id" : 5, "item" : "xyz", "price" : 5, "quantity" : 10, "date" : ISODate("2021-02-15T09:05:00Z") }, - { "_id" : 6, "item" : "xyz", "price" : 5, "quantity" : 5, "date" : ISODate("2021-02-15T12:05:10Z") }, - { "_id" : 7, "item" : "xyz", "price" : 5, "quantity" : 10, "date" : ISODate("2021-02-15T14:12:12Z") }, - { "_id" : 8, "item" : "abc", "price" : 10, "quantity" : 5, "date" : ISODate("2021-03-16T20:20:13Z") } - ]) - -This operation returns a count of the documents in the stage. - -.. code-block:: javascript - - db.sales.aggregate( - [ - { - $group: - { - _id: null, - count: { $count: { } } - } - } - ] - ) - - -The operation returns the following results: - -.. code-block:: javascript - - { "_id" : null, "count" : 8 } diff --git a/source/reference/operator/aggregation/count-accumulator.txt b/source/reference/operator/aggregation/count-accumulator.txt index 49be7222b09..57ab262b2d7 100644 --- a/source/reference/operator/aggregation/count-accumulator.txt +++ b/source/reference/operator/aggregation/count-accumulator.txt @@ -19,8 +19,7 @@ Definition Returns the number of documents. -.. admonition:: Disambiguation - :class: note +.. note:: Disambiguation This page describes the ``$count`` aggregation accumulator. For the ``$count`` aggregation pipeline stage, see :pipeline:`$count @@ -47,6 +46,16 @@ Returns the number of documents. :group:`$count` does not accept any parameters. +Behavior +-------- + +:group:`$count` is functionally equivalent to using ``{ $sum : 1 }`` +within the :pipeline:`$group` stage. + +.. seealso:: + + :group:`$sum` + Examples -------- diff --git a/source/reference/operator/aggregation/count.txt b/source/reference/operator/aggregation/count.txt index 391b0eae446..e7638c62b5f 100644 --- a/source/reference/operator/aggregation/count.txt +++ b/source/reference/operator/aggregation/count.txt @@ -20,8 +20,7 @@ Definition Passes a document to the next stage that contains a count of the number of documents input to the stage. - .. admonition:: Disambiguation - :class: note + .. note:: Disambiguation This page describes the ``$count`` aggregation pipeline stage. For the ``$count`` aggregation accumulator, see :group:`$count diff --git a/source/reference/operator/aggregation/first.txt b/source/reference/operator/aggregation/first.txt index f978338b41c..93d25debe6b 100644 --- a/source/reference/operator/aggregation/first.txt +++ b/source/reference/operator/aggregation/first.txt @@ -23,8 +23,7 @@ documents. Only meaningful when documents are in a defined order. .. include:: /includes/extracts/fact-aggregation-accumulator-first.rst -.. admonition:: Disambiguation - :class: note +.. note:: Disambiguation This page describes the :group:`$first` aggregation accumulator. For the :expression:`$first` array operator, see :expression:`$first diff --git a/source/reference/operator/aggregation/integral.txt b/source/reference/operator/aggregation/integral.txt index 953071ff3aa..e38ccfb19bd 100644 --- a/source/reference/operator/aggregation/integral.txt +++ b/source/reference/operator/aggregation/integral.txt @@ -59,9 +59,9 @@ documents forming a trapezoid using the: Specifies the :ref:`expression ` to evaluate. You must provide an expression that returns a number. - * - :ref:`unit ` + * - :ref:`unit ` - - .. _integral-outputUnit: + - .. _integral-unit: .. include:: /includes/outputUnit-behavior.rst diff --git a/source/reference/operator/aggregation/last.txt b/source/reference/operator/aggregation/last.txt index 7d90fe71950..9dfaba73f4e 100644 --- a/source/reference/operator/aggregation/last.txt +++ b/source/reference/operator/aggregation/last.txt @@ -23,8 +23,7 @@ Only meaningful when documents are in a defined order. .. include:: /includes/extracts/fact-aggregation-accumulator-last.rst -.. admonition:: Disambiguation - :class: note +.. note:: Disambiguation This page describes the :group:`$last` aggregation accumulator. For the :expression:`$last` array operator, see :expression:`$last (array diff --git a/source/release-notes/5.0.txt b/source/release-notes/5.0.txt index eb1ad40fca4..2ad7fda9fdb 100644 --- a/source/release-notes/5.0.txt +++ b/source/release-notes/5.0.txt @@ -40,8 +40,9 @@ MongoDB 5.0 introduces the following aggregation operators: * - :group:`$count` - :group:`$count (aggregation accumulator) <$count>` - provides a count of all documents when used in a - :pipeline:`$group (aggregation) <$group>` pipeline stage. + provides a count of all documents when used in the existing + pipeline :pipeline:`$group (aggregation) <$group>` stage and the + new MongoDB 5.0 :pipeline:`$setWindowFields` stage. .. note:: Disambiguation