Skip to content

Commit be131dd

Browse files
committed
PYTHON-2802 Link to create command docs in create_collection (#678)
PYTHON-2840 Document "let" support for aggregation. (cherry picked from commit 9833ce0)
1 parent 5ba67d6 commit be131dd

File tree

2 files changed

+63
-52
lines changed

2 files changed

+63
-52
lines changed

pymongo/collection.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,24 +2423,6 @@ def aggregate(self, pipeline, session=None, **kwargs):
24232423
"""Perform an aggregation using the aggregation framework on this
24242424
collection.
24252425
2426-
All optional `aggregate command`_ parameters should be passed as
2427-
keyword arguments to this method. Valid options include, but are not
2428-
limited to:
2429-
2430-
- `allowDiskUse` (bool): Enables writing to temporary files. When set
2431-
to True, aggregation stages can write data to the _tmp subdirectory
2432-
of the --dbpath directory. The default is False.
2433-
- `maxTimeMS` (int): The maximum amount of time to allow the operation
2434-
to run in milliseconds.
2435-
- `batchSize` (int): The maximum number of documents to return per
2436-
batch. Ignored if the connected mongod or mongos does not support
2437-
returning aggregate results using a cursor, or `useCursor` is
2438-
``False``.
2439-
- `collation` (optional): An instance of
2440-
:class:`~pymongo.collation.Collation`. This option is only supported
2441-
on MongoDB 3.4 and above.
2442-
- `useCursor` (bool): Deprecated. Will be removed in PyMongo 4.0.
2443-
24442426
The :meth:`aggregate` method obeys the :attr:`read_preference` of this
24452427
:class:`Collection`, except when ``$out`` or ``$merge`` are used, in
24462428
which case :attr:`~pymongo.read_preferences.ReadPreference.PRIMARY`
@@ -2458,7 +2440,30 @@ def aggregate(self, pipeline, session=None, **kwargs):
24582440
- `pipeline`: a list of aggregation pipeline stages
24592441
- `session` (optional): a
24602442
:class:`~pymongo.client_session.ClientSession`.
2461-
- `**kwargs` (optional): See list of options above.
2443+
- `**kwargs` (optional): extra `aggregate command`_ parameters.
2444+
2445+
All optional `aggregate command`_ parameters should be passed as
2446+
keyword arguments to this method. Valid options include, but are not
2447+
limited to:
2448+
2449+
- `allowDiskUse` (bool): Enables writing to temporary files. When set
2450+
to True, aggregation stages can write data to the _tmp subdirectory
2451+
of the --dbpath directory. The default is False.
2452+
- `maxTimeMS` (int): The maximum amount of time to allow the operation
2453+
to run in milliseconds.
2454+
- `batchSize` (int): The maximum number of documents to return per
2455+
batch. Ignored if the connected mongod or mongos does not support
2456+
returning aggregate results using a cursor, or `useCursor` is
2457+
``False``.
2458+
- `collation` (optional): An instance of
2459+
:class:`~pymongo.collation.Collation`. This option is only supported
2460+
on MongoDB 3.4 and above.
2461+
- `let` (dict): A dict of parameter names and values. Values must be
2462+
constant or closed expressions that do not reference document
2463+
fields. Parameters can then be accessed as variables in an
2464+
aggregate expression context (e.g. ``"$$var"``). This option is
2465+
only supported on MongoDB >= 5.0.
2466+
- `useCursor` (bool): Deprecated. Will be removed in PyMongo 4.0.
24622467
24632468
:Returns:
24642469
A :class:`~pymongo.command_cursor.CommandCursor` over the result

pymongo/database.py

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -357,22 +357,6 @@ def create_collection(self, name, codec_options=None,
357357
creation. :class:`~pymongo.errors.CollectionInvalid` will be
358358
raised if the collection already exists.
359359
360-
Options should be passed as keyword arguments to this method. Supported
361-
options vary with MongoDB release. Some examples include:
362-
363-
- ``size``: desired initial size for the collection (in
364-
bytes). For capped collections this size is the max
365-
size of the collection.
366-
- ``capped``: if True, this is a capped collection
367-
- ``max``: maximum number of objects if capped (optional)
368-
- ``timeseries``: a document specifying configuration options for
369-
timeseries collections
370-
- ``expireAfterSeconds``: the number of seconds after which a
371-
document in a timeseries collection expires
372-
373-
See the MongoDB documentation for a full list of supported options by
374-
server version.
375-
376360
:Parameters:
377361
- `name`: the name of the collection to create
378362
- `codec_options` (optional): An instance of
@@ -395,7 +379,21 @@ def create_collection(self, name, codec_options=None,
395379
- `session` (optional): a
396380
:class:`~pymongo.client_session.ClientSession`.
397381
- `**kwargs` (optional): additional keyword arguments will
398-
be passed as options for the create collection command
382+
be passed as options for the `create collection command`_
383+
384+
All optional `create collection command`_ parameters should be passed
385+
as keyword arguments to this method. Valid options include, but are not
386+
limited to:
387+
388+
- ``size``: desired initial size for the collection (in
389+
bytes). For capped collections this size is the max
390+
size of the collection.
391+
- ``capped``: if True, this is a capped collection
392+
- ``max``: maximum number of objects if capped (optional)
393+
- ``timeseries``: a document specifying configuration options for
394+
timeseries collections
395+
- ``expireAfterSeconds``: the number of seconds after which a
396+
document in a timeseries collection expires
399397
400398
.. versionchanged:: 3.11
401399
This method is now supported inside multi-document transactions
@@ -412,6 +410,9 @@ def create_collection(self, name, codec_options=None,
412410
413411
.. versionchanged:: 2.2
414412
Removed deprecated argument: options
413+
414+
.. _create collection command:
415+
https://docs.mongodb.com/manual/reference/command/create
415416
"""
416417
with self.__client._tmp_session(session) as s:
417418
# Skip this check in a transaction where listCollections is not
@@ -476,21 +477,6 @@ def aggregate(self, pipeline, session=None, **kwargs):
476477
for operation in cursor:
477478
print(operation)
478479
479-
All optional `aggregate command`_ parameters should be passed as
480-
keyword arguments to this method. Valid options include, but are not
481-
limited to:
482-
483-
- `allowDiskUse` (bool): Enables writing to temporary files. When set
484-
to True, aggregation stages can write data to the _tmp subdirectory
485-
of the --dbpath directory. The default is False.
486-
- `maxTimeMS` (int): The maximum amount of time to allow the operation
487-
to run in milliseconds.
488-
- `batchSize` (int): The maximum number of documents to return per
489-
batch. Ignored if the connected mongod or mongos does not support
490-
returning aggregate results using a cursor.
491-
- `collation` (optional): An instance of
492-
:class:`~pymongo.collation.Collation`.
493-
494480
The :meth:`aggregate` method obeys the :attr:`read_preference` of this
495481
:class:`Database`, except when ``$out`` or ``$merge`` are used, in
496482
which case :attr:`~pymongo.read_preferences.ReadPreference.PRIMARY`
@@ -506,7 +492,27 @@ def aggregate(self, pipeline, session=None, **kwargs):
506492
- `pipeline`: a list of aggregation pipeline stages
507493
- `session` (optional): a
508494
:class:`~pymongo.client_session.ClientSession`.
509-
- `**kwargs` (optional): See list of options above.
495+
- `**kwargs` (optional): extra `aggregate command`_ parameters.
496+
497+
All optional `aggregate command`_ parameters should be passed as
498+
keyword arguments to this method. Valid options include, but are not
499+
limited to:
500+
501+
- `allowDiskUse` (bool): Enables writing to temporary files. When set
502+
to True, aggregation stages can write data to the _tmp subdirectory
503+
of the --dbpath directory. The default is False.
504+
- `maxTimeMS` (int): The maximum amount of time to allow the operation
505+
to run in milliseconds.
506+
- `batchSize` (int): The maximum number of documents to return per
507+
batch. Ignored if the connected mongod or mongos does not support
508+
returning aggregate results using a cursor.
509+
- `collation` (optional): An instance of
510+
:class:`~pymongo.collation.Collation`.
511+
- `let` (dict): A dict of parameter names and values. Values must be
512+
constant or closed expressions that do not reference document
513+
fields. Parameters can then be accessed as variables in an
514+
aggregate expression context (e.g. ``"$$var"``). This option is
515+
only supported on MongoDB >= 5.0.
510516
511517
:Returns:
512518
A :class:`~pymongo.command_cursor.CommandCursor` over the result

0 commit comments

Comments
 (0)