MongoDBDatabase-aggregate.txt 1.74 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
==============================
MongoDB\\Database::aggregate()
==============================

.. versionadded:: 1.5

.. default-domain:: mongodb

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

Definition
----------

.. phpmethod:: MongoDB\\Database::aggregate()

   Runs a specified :manual:`admin/diagnostic pipeline
   </reference/operator/aggregation-pipeline/#db-aggregate-stages>` which does
   not require an underlying collection. For aggregations on collection data,
   see :phpmethod:`MongoDB\\Collection::aggregate()`.

   .. code-block:: php

      function aggregate(array $pipeline, array $options = []): Traversable

   This method has the following parameters:

   .. include:: /includes/apiargs/MongoDBDatabase-method-aggregate-param.rst

   The ``$options`` parameter supports the following options:

   .. include:: /includes/apiargs/MongoDBDatabase-method-aggregate-option.rst

Return Values
-------------

A :php:`MongoDB\\Driver\\Cursor <class.mongodb-driver-cursor>` or
:php:`ArrayIterator <arrayiterator>` object. In both cases, the return value
will be :php:`Traversable <traversable>`.

Errors/Exceptions
-----------------

.. include:: /includes/extracts/error-unexpectedvalueexception.rst
.. include:: /includes/extracts/error-unsupportedexception.rst
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst

.. _php-db-agg-method-behavior:

.. todo: add examples

See Also
--------

- :phpmethod:`MongoDB\\Collection::aggregate()`
- :manual:`aggregate </reference/command/aggregate>` command reference in the
  MongoDB manual
- :manual:`Aggregation Pipeline </core/aggregation-pipeline>` documentation in
  the MongoDB Manual