Skip to content
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

Merge cpp-standardization into master #52

Merged
merged 37 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d0c5856
DOCSP-39788 - Issues and Help (#14)
mongoKart Jun 24, 2024
12277b1
DOCSP-40785 - Create Instance and Client (#17)
mongoKart Jun 26, 2024
27d3135
DOCSP-39789 - Compatibility (#15)
mongoKart Jun 26, 2024
918c0fc
DOCSP-40540: Get started (#13)
norareidy Jun 26, 2024
332f611
DOCSP-39814: Retrieve guide (#16)
norareidy Jun 26, 2024
97480e4
DOCSP-40791: Insert documents guide (#19)
norareidy Jun 27, 2024
dd3c7e8
DOCSP-40797: Specify a query (#21)
norareidy Jun 28, 2024
e22bb3d
DOCSP-40799: Projection guide (#23)
norareidy Jun 28, 2024
01ac70c
DOCSP-40801: Count documents (#27)
norareidy Jul 3, 2024
4c2bf0f
DOCSP-40802: Distinct values (#28)
norareidy Jul 3, 2024
0ab06cb
DOCSP-40800: Specify documents to return (#24)
norareidy Jul 5, 2024
71b2761
DOCSP-40811 Authentication Mechanisms (#22)
jordan-smith721 Jul 10, 2024
b9d4a7a
DOCSP-40803: Cursor guide (#30)
norareidy Jul 10, 2024
8ad2932
DOCSP-40804: Monitor changes (#31)
norareidy Jul 10, 2024
596e550
DOCSP-40796: Read operations landing (#32)
norareidy Jul 10, 2024
91e26d3
DOCSP-40806 Indexes (#35)
jordan-smith721 Jul 12, 2024
f1a09f5
DOCSP-40812 Encryption (#26)
jordan-smith721 Jul 12, 2024
05a73e0
DOCSP-40792: Delete guide (#33)
norareidy Jul 12, 2024
cf31fd6
DOCSP-40793: Update guide (#34)
norareidy Jul 12, 2024
d27d426
DOCSP-40805 Indexes landing page (#36)
jordan-smith721 Jul 15, 2024
574c38a
DOCSP-40794: Bulk write guide (#37)
norareidy Jul 15, 2024
1e7a002
DOCSP-40790: Write operations landing page (#38)
norareidy Jul 17, 2024
55c5953
DOCSP-40815: Time series (#41)
norareidy Jul 17, 2024
f1eed91
DOCSP-40786 - Connection Targets (#20)
mongoKart Jul 17, 2024
84e7367
DOCSP-40813: Data formats landing page (#42)
norareidy Jul 17, 2024
c2b384d
DOCSP-40810 Secure Data landing page (#25)
jordan-smith721 Jul 18, 2024
84cb128
DOCSP-40809: Aggregation guide (#40)
norareidy Jul 18, 2024
426c6f5
remove brackets from instances (#44)
jordan-smith721 Jul 19, 2024
dc44ad4
api link (#45)
mongoKart Jul 19, 2024
a62212a
DOCSP-40787 - Connection Options (#39)
mongoKart Jul 23, 2024
086ed81
DOCSP-40789 - Stable API (#48)
mongoKart Jul 24, 2024
f08d494
DOCSP-40788 - Network Compression (#47)
mongoKart Jul 24, 2024
7f50bdf
DOCSP-40816 - Upgrade (#43)
mongoKart Jul 24, 2024
54c6aa5
DOCSP-41507 - TLS (#50)
mongoKart Aug 1, 2024
ad65dcb
DOCSP-40784: Connect landing page (#51)
norareidy Aug 2, 2024
5749860
DOCSP-40818 - What's New (#49)
mongoKart Aug 2, 2024
4c5211e
merge conflicts
mongoKart Aug 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions snooty.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ intersphinx = [

toc_landing_pages = [
"/installation",
"/api-abi-versioning"
]
"/api-abi-versioning",
"/get-started",
"/connect",
"/read",
"/write",
"/indexes",
"/security",
"/data-formats",
]

sharedinclude_root = "https://raw.githubusercontent.com/10gen/docs-shared/main/"

Expand All @@ -20,4 +27,8 @@ driver-long = "MongoDB C++ Driver"
driver-short = "C++ driver"
version = "3.10"
full-version = "{+version+}.2"
api = "https://mongocxx.org/api/current"
api = "https://mongocxx.org/api/current"
string-data-type = "``string``"
int-data-type = "``int``"
stable-api = "Stable API"
mdb-server = "MongoDB Server"
195 changes: 195 additions & 0 deletions source/aggregation.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
.. _cpp-aggregation:

====================================
Transform Your Data with Aggregation
====================================

.. facet::
:name: genre
:values: reference

.. meta::
:keywords: code example, transform, computed, pipeline
:description: Learn how to use the C++ driver to perform aggregation operations.

.. contents:: On this page
:local:
:backlinks: none
:depth: 2
:class: singlecol

.. TODO:
.. toctree::
:titlesonly:
:maxdepth: 1

/aggregation/aggregation-tutorials

Overview
--------

In this guide, you can learn how to use the {+driver-short+} to perform
**aggregation operations**.

Aggregation operations process data in your MongoDB collections and
return computed results. The MongoDB Aggregation framework, which is
part of the Query API, is modeled on the concept of data processing
pipelines. Documents enter a pipeline that contains one or more stages,
and this pipeline transforms the documents into an aggregated result.

An aggregation operation is similar to a car factory. A car factory has
an assembly line, which contains assembly stations with specialized
tools to do specific jobs, like drills and welders. Raw parts enter the
factory, and then the assembly line transforms and assembles them into a
finished product.

The **aggregation pipeline** is the assembly line, **aggregation stages** are the
assembly stations, and **operator expressions** are the
specialized tools.

Aggregation Versus Find Operations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can use find operations to perform the following actions:

- Select which documents to return
- Select which fields to return
- Sort the results

You can use aggregation operations to perform the following actions:

- Run find operations
- Rename fields
- Calculate fields
- Summarize data
- Group values

Limitations
~~~~~~~~~~~

Keep the following limitations in mind when using aggregation operations:

- Returned documents cannot violate the
:manual:`BSON document size limit </reference/limits/#mongodb-limit-BSON-Document-Size>`
of 16 megabytes.
- Pipeline stages have a memory limit of 100 megabytes by default. You can exceed this
limit by setting the ``allow_disk_use`` field of a ``mongocxx::options::aggregate``
instance to ``true``.

.. important:: $graphLookup Exception

The :manual:`$graphLookup
</reference/operator/aggregation/graphLookup/>` stage has a strict
memory limit of 100 megabytes and ignores the ``allow_disk_use`` field.

.. _cpp-aggregation-example:

Aggregation Example
-------------------

.. note::

The examples in this guide use the ``restaurants`` collection in the ``sample_restaurants``
database from the :atlas:`Atlas sample datasets </sample-data>`. To learn how to create a
free MongoDB Atlas cluster and load the sample datasets, see the :atlas:`Get Started with Atlas
</getting-started>` guide.

To perform an aggregation, pass a ``mongocxx::pipeline`` instance containing the aggregation
stages to the ``collection.aggregate()`` method.

The following code example produces a count of the number of bakeries in each borough
of New York. To do so, it uses an aggregation pipeline that contains the following stages:

- :manual:`$match </reference/operator/aggregation/match/>` stage to filter for documents
in which the ``cuisine`` field contains the value ``"Bakery"``

- :manual:`$group </reference/operator/aggregation/group/>` stage to group the matching
documents by the ``borough`` field, accumulating a count of documents for each distinct
value

.. io-code-block::

.. input:: /includes/aggregation.cpp
:start-after: start-match-group
:end-before: end-match-group
:language: cpp
:dedent:

.. output::

{ "_id" : "Brooklyn", "count" : 173 }
{ "_id" : "Queens", "count" : 204 }
{ "_id" : "Bronx", "count" : 71 }
{ "_id" : "Staten Island", "count" : 20 }
{ "_id" : "Missing", "count" : 2 }
{ "_id" : "Manhattan", "count" : 221 }

Explain an Aggregation
~~~~~~~~~~~~~~~~~~~~~~

To view information about how MongoDB executes your operation, you can
instruct the MongoDB query planner to **explain** it. When MongoDB explains
an operation, it returns **execution plans** and performance statistics.
An execution plan is a potential way MongoDB can complete an operation.
When you instruct MongoDB to explain an operation, it returns both the
plan MongoDB executed and any rejected execution plans.

To explain an aggregation operation, run the ``explain`` database command by specifying
the command in a BSON document and passing it as an argument to the ``run_command()``
method.

The following example instructs MongoDB to explain the aggregation operation from the
preceding :ref:`cpp-aggregation-example`:

.. io-code-block::

.. input:: /includes/aggregation.cpp
:start-after: start-explain
:end-before: end-explain
:language: cpp
:dedent:

.. output::

{ "explainVersion" : "2", "queryPlanner" : { "namespace" : "sample_restaurants.restaurants",
"indexFilterSet" : false, "parsedQuery" : { "cuisine" : { "$eq" : "Bakery" } }, "queryHash":
"...", "planCacheKey" : "...", "optimizedPipeline" : true, "maxIndexedOrSolutionsReached":
false, "maxIndexedAndSolutionsReached" : false, "maxScansToExplodeReached" : false,
"winningPlan" : { ... }
... }


Additional Information
----------------------

MongoDB Server Manual
~~~~~~~~~~~~~~~~~~~~~

To view a full list of expression operators, see :manual:`Aggregation
Operators. </reference/operator/aggregation/>`

To learn about assembling an aggregation pipeline and view examples, see
:manual:`Aggregation Pipeline. </core/aggregation-pipeline/>`

To learn more about creating pipeline stages, see :manual:`Aggregation
Stages. </reference/operator/aggregation-pipeline/>`

To learn more about explaining MongoDB operations, see
:manual:`Explain Output </reference/explain-results/>` and
:manual:`Query Plans. </core/query-plans/>`

.. TODO:
Aggregation Tutorials
~~~~~~~~~~~~~~~~~~~~~

.. To view step-by-step explanations of common aggregation tasks, see
.. :ref:`cpp-aggregation-tutorials-landing`.

API Documentation
~~~~~~~~~~~~~~~~~

For more information about executing aggregation operations with the {+driver-short+},
see the following API documentation:

- `aggregate() <{+api+}/classmongocxx_1_1v__noabi_1_1collection.html#a480f6d0f9986d43b1d17d6ed8876941d>`__
- `mongocxx::options::aggregate <{+api+}/classmongocxx_1_1v__noabi_1_1options_1_1aggregate.html>`__
45 changes: 45 additions & 0 deletions source/compatibility.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.. _cpp-compatibility-tables:

=============
Compatibility
=============

.. contents:: On this page
:local:
:backlinks: none
:depth: 2
:class: singlecol

.. facet::
:name: genre
:values: reference

.. meta::
:keywords: backwards compatibility, versions, upgrade

MongoDB Compatibility
---------------------

The following compatibility table specifies the recommended version or versions
of the {+driver-long+} for use with a specific version of MongoDB.

The first column lists the driver version.

.. sharedinclude:: dbx/lifecycle-schedule-callout.rst

.. sharedinclude:: dbx/compatibility-table-legend.rst

.. include:: /includes/mongodb-compatibility-table-cxx.rst

Language Compatibility
----------------------

The following compatibility table specifies the recommended version of the
{+driver-long+} for use with a specific version of C++.

The first column lists the driver version.

.. include:: /includes/language-compatibility-table-cxx.rst

For more information on how to read the compatibility tables, see our guide on
:ref:`MongoDB Compatibility Tables. <about-driver-compatibility>`
Loading
Loading