Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
37 changes: 21 additions & 16 deletions pymongo/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2175,21 +2175,6 @@ def aggregate(self, pipeline, session=None, **kwargs):
"""Perform an aggregation using the aggregation framework on this
collection.

All optional `aggregate command`_ parameters should be passed as
keyword arguments to this method. Valid options include, but are not
limited to:

- `allowDiskUse` (bool): Enables writing to temporary files. When set
to True, aggregation stages can write data to the _tmp subdirectory
of the --dbpath directory. The default is False.
- `maxTimeMS` (int): The maximum amount of time to allow the operation
to run in milliseconds.
- `batchSize` (int): The maximum number of documents to return per
batch.
- `collation` (optional): An instance of
:class:`~pymongo.collation.Collation`. This option is only supported
on MongoDB 3.4 and above.

The :meth:`aggregate` method obeys the :attr:`read_preference` of this
:class:`Collection`, except when ``$out`` or ``$merge`` are used, in
which case :attr:`~pymongo.read_preferences.ReadPreference.PRIMARY`
Expand All @@ -2207,7 +2192,27 @@ def aggregate(self, pipeline, session=None, **kwargs):
- `pipeline`: a list of aggregation pipeline stages
- `session` (optional): a
:class:`~pymongo.client_session.ClientSession`.
- `**kwargs` (optional): See list of options above.
- `**kwargs` (optional): extra `aggregate command`_ parameters.

All optional `aggregate command`_ parameters should be passed as
keyword arguments to this method. Valid options include, but are not
limited to:

- `allowDiskUse` (bool): Enables writing to temporary files. When set
to True, aggregation stages can write data to the _tmp subdirectory
of the --dbpath directory. The default is False.
- `maxTimeMS` (int): The maximum amount of time to allow the operation
to run in milliseconds.
- `batchSize` (int): The maximum number of documents to return per
batch. Ignored if the connected mongod or mongos does not support
returning aggregate results using a cursor.
- `collation` (optional): An instance of
:class:`~pymongo.collation.Collation`.
- `let` (dict): A dict of parameter names and values. Values must be
constant or closed expressions that do not reference document
fields. Parameters can then be accessed as variables in an
aggregate expression context (e.g. ``"$$var"``). This option is
only supported on MongoDB >= 5.0.

:Returns:
A :class:`~pymongo.command_cursor.CommandCursor` over the result
Expand Down
72 changes: 39 additions & 33 deletions pymongo/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,22 +248,6 @@ def create_collection(self, name, codec_options=None,
creation. :class:`~pymongo.errors.CollectionInvalid` will be
raised if the collection already exists.

Options should be passed as keyword arguments to this method. Supported
options vary with MongoDB release. Some examples include:

- "size": desired initial size for the collection (in
bytes). For capped collections this size is the max
size of the collection.
- "capped": if True, this is a capped collection
- "max": maximum number of objects if capped (optional)
- `timeseries`: a document specifying configuration options for
timeseries collections
- `expireAfterSeconds`: the number of seconds after which a
document in a timeseries collection expires

See the MongoDB documentation for a full list of supported options by
server version.

:Parameters:
- `name`: the name of the collection to create
- `codec_options` (optional): An instance of
Expand All @@ -286,7 +270,21 @@ def create_collection(self, name, codec_options=None,
- `session` (optional): a
:class:`~pymongo.client_session.ClientSession`.
- `**kwargs` (optional): additional keyword arguments will
be passed as options for the create collection command
be passed as options for the `create collection command`_

All optional `create collection command`_ parameters should be passed
as keyword arguments to this method. Valid options include, but are not
limited to:

- ``size``: desired initial size for the collection (in
bytes). For capped collections this size is the max
size of the collection.
- ``capped``: if True, this is a capped collection
- ``max``: maximum number of objects if capped (optional)
- ``timeseries``: a document specifying configuration options for
timeseries collections
- ``expireAfterSeconds``: the number of seconds after which a
document in a timeseries collection expires

.. versionchanged:: 3.11
This method is now supported inside multi-document transactions
Expand All @@ -303,6 +301,9 @@ def create_collection(self, name, codec_options=None,

.. versionchanged:: 2.2
Removed deprecated argument: options

.. _create collection command:
https://docs.mongodb.com/manual/reference/command/create
"""
with self.__client._tmp_session(session) as s:
# Skip this check in a transaction where listCollections is not
Expand Down Expand Up @@ -331,21 +332,6 @@ def aggregate(self, pipeline, session=None, **kwargs):
for operation in cursor:
print(operation)

All optional `aggregate command`_ parameters should be passed as
keyword arguments to this method. Valid options include, but are not
limited to:

- `allowDiskUse` (bool): Enables writing to temporary files. When set
to True, aggregation stages can write data to the _tmp subdirectory
of the --dbpath directory. The default is False.
- `maxTimeMS` (int): The maximum amount of time to allow the operation
to run in milliseconds.
- `batchSize` (int): The maximum number of documents to return per
batch. Ignored if the connected mongod or mongos does not support
returning aggregate results using a cursor.
- `collation` (optional): An instance of
:class:`~pymongo.collation.Collation`.

The :meth:`aggregate` method obeys the :attr:`read_preference` of this
:class:`Database`, except when ``$out`` or ``$merge`` are used, in
which case :attr:`~pymongo.read_preferences.ReadPreference.PRIMARY`
Expand All @@ -361,7 +347,27 @@ def aggregate(self, pipeline, session=None, **kwargs):
- `pipeline`: a list of aggregation pipeline stages
- `session` (optional): a
:class:`~pymongo.client_session.ClientSession`.
- `**kwargs` (optional): See list of options above.
- `**kwargs` (optional): extra `aggregate command`_ parameters.

All optional `aggregate command`_ parameters should be passed as
keyword arguments to this method. Valid options include, but are not
limited to:

- `allowDiskUse` (bool): Enables writing to temporary files. When set
to True, aggregation stages can write data to the _tmp subdirectory
of the --dbpath directory. The default is False.
- `maxTimeMS` (int): The maximum amount of time to allow the operation
to run in milliseconds.
- `batchSize` (int): The maximum number of documents to return per
batch. Ignored if the connected mongod or mongos does not support
returning aggregate results using a cursor.
- `collation` (optional): An instance of
:class:`~pymongo.collation.Collation`.
- `let` (dict): A dict of parameter names and values. Values must be
constant or closed expressions that do not reference document
fields. Parameters can then be accessed as variables in an
aggregate expression context (e.g. ``"$$var"``). This option is
only supported on MongoDB >= 5.0.

:Returns:
A :class:`~pymongo.command_cursor.CommandCursor` over the result
Expand Down