Skip to content

Commit 9833ce0

Browse files
authored
PYTHON-2802 Link to create command docs in create_collection (#678)
PYTHON-2840 Document "let" support for aggregation.
1 parent c93194a commit 9833ce0

File tree

2 files changed

+60
-49
lines changed

2 files changed

+60
-49
lines changed

pymongo/collection.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,21 +2175,6 @@ def aggregate(self, pipeline, session=None, **kwargs):
21752175
"""Perform an aggregation using the aggregation framework on this
21762176
collection.
21772177
2178-
All optional `aggregate command`_ parameters should be passed as
2179-
keyword arguments to this method. Valid options include, but are not
2180-
limited to:
2181-
2182-
- `allowDiskUse` (bool): Enables writing to temporary files. When set
2183-
to True, aggregation stages can write data to the _tmp subdirectory
2184-
of the --dbpath directory. The default is False.
2185-
- `maxTimeMS` (int): The maximum amount of time to allow the operation
2186-
to run in milliseconds.
2187-
- `batchSize` (int): The maximum number of documents to return per
2188-
batch.
2189-
- `collation` (optional): An instance of
2190-
:class:`~pymongo.collation.Collation`. This option is only supported
2191-
on MongoDB 3.4 and above.
2192-
21932178
The :meth:`aggregate` method obeys the :attr:`read_preference` of this
21942179
:class:`Collection`, except when ``$out`` or ``$merge`` are used, in
21952180
which case :attr:`~pymongo.read_preferences.ReadPreference.PRIMARY`
@@ -2207,7 +2192,27 @@ def aggregate(self, pipeline, session=None, **kwargs):
22072192
- `pipeline`: a list of aggregation pipeline stages
22082193
- `session` (optional): a
22092194
:class:`~pymongo.client_session.ClientSession`.
2210-
- `**kwargs` (optional): See list of options above.
2195+
- `**kwargs` (optional): extra `aggregate command`_ parameters.
2196+
2197+
All optional `aggregate command`_ parameters should be passed as
2198+
keyword arguments to this method. Valid options include, but are not
2199+
limited to:
2200+
2201+
- `allowDiskUse` (bool): Enables writing to temporary files. When set
2202+
to True, aggregation stages can write data to the _tmp subdirectory
2203+
of the --dbpath directory. The default is False.
2204+
- `maxTimeMS` (int): The maximum amount of time to allow the operation
2205+
to run in milliseconds.
2206+
- `batchSize` (int): The maximum number of documents to return per
2207+
batch. Ignored if the connected mongod or mongos does not support
2208+
returning aggregate results using a cursor.
2209+
- `collation` (optional): An instance of
2210+
:class:`~pymongo.collation.Collation`.
2211+
- `let` (dict): A dict of parameter names and values. Values must be
2212+
constant or closed expressions that do not reference document
2213+
fields. Parameters can then be accessed as variables in an
2214+
aggregate expression context (e.g. ``"$$var"``). This option is
2215+
only supported on MongoDB >= 5.0.
22112216
22122217
:Returns:
22132218
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
@@ -248,22 +248,6 @@ def create_collection(self, name, codec_options=None,
248248
creation. :class:`~pymongo.errors.CollectionInvalid` will be
249249
raised if the collection already exists.
250250
251-
Options should be passed as keyword arguments to this method. Supported
252-
options vary with MongoDB release. Some examples include:
253-
254-
- "size": desired initial size for the collection (in
255-
bytes). For capped collections this size is the max
256-
size of the collection.
257-
- "capped": if True, this is a capped collection
258-
- "max": maximum number of objects if capped (optional)
259-
- `timeseries`: a document specifying configuration options for
260-
timeseries collections
261-
- `expireAfterSeconds`: the number of seconds after which a
262-
document in a timeseries collection expires
263-
264-
See the MongoDB documentation for a full list of supported options by
265-
server version.
266-
267251
:Parameters:
268252
- `name`: the name of the collection to create
269253
- `codec_options` (optional): An instance of
@@ -286,7 +270,21 @@ def create_collection(self, name, codec_options=None,
286270
- `session` (optional): a
287271
:class:`~pymongo.client_session.ClientSession`.
288272
- `**kwargs` (optional): additional keyword arguments will
289-
be passed as options for the create collection command
273+
be passed as options for the `create collection command`_
274+
275+
All optional `create collection command`_ parameters should be passed
276+
as keyword arguments to this method. Valid options include, but are not
277+
limited to:
278+
279+
- ``size``: desired initial size for the collection (in
280+
bytes). For capped collections this size is the max
281+
size of the collection.
282+
- ``capped``: if True, this is a capped collection
283+
- ``max``: maximum number of objects if capped (optional)
284+
- ``timeseries``: a document specifying configuration options for
285+
timeseries collections
286+
- ``expireAfterSeconds``: the number of seconds after which a
287+
document in a timeseries collection expires
290288
291289
.. versionchanged:: 3.11
292290
This method is now supported inside multi-document transactions
@@ -303,6 +301,9 @@ def create_collection(self, name, codec_options=None,
303301
304302
.. versionchanged:: 2.2
305303
Removed deprecated argument: options
304+
305+
.. _create collection command:
306+
https://docs.mongodb.com/manual/reference/command/create
306307
"""
307308
with self.__client._tmp_session(session) as s:
308309
# Skip this check in a transaction where listCollections is not
@@ -331,21 +332,6 @@ def aggregate(self, pipeline, session=None, **kwargs):
331332
for operation in cursor:
332333
print(operation)
333334
334-
All optional `aggregate command`_ parameters should be passed as
335-
keyword arguments to this method. Valid options include, but are not
336-
limited to:
337-
338-
- `allowDiskUse` (bool): Enables writing to temporary files. When set
339-
to True, aggregation stages can write data to the _tmp subdirectory
340-
of the --dbpath directory. The default is False.
341-
- `maxTimeMS` (int): The maximum amount of time to allow the operation
342-
to run in milliseconds.
343-
- `batchSize` (int): The maximum number of documents to return per
344-
batch. Ignored if the connected mongod or mongos does not support
345-
returning aggregate results using a cursor.
346-
- `collation` (optional): An instance of
347-
:class:`~pymongo.collation.Collation`.
348-
349335
The :meth:`aggregate` method obeys the :attr:`read_preference` of this
350336
:class:`Database`, except when ``$out`` or ``$merge`` are used, in
351337
which case :attr:`~pymongo.read_preferences.ReadPreference.PRIMARY`
@@ -361,7 +347,27 @@ def aggregate(self, pipeline, session=None, **kwargs):
361347
- `pipeline`: a list of aggregation pipeline stages
362348
- `session` (optional): a
363349
:class:`~pymongo.client_session.ClientSession`.
364-
- `**kwargs` (optional): See list of options above.
350+
- `**kwargs` (optional): extra `aggregate command`_ parameters.
351+
352+
All optional `aggregate command`_ parameters should be passed as
353+
keyword arguments to this method. Valid options include, but are not
354+
limited to:
355+
356+
- `allowDiskUse` (bool): Enables writing to temporary files. When set
357+
to True, aggregation stages can write data to the _tmp subdirectory
358+
of the --dbpath directory. The default is False.
359+
- `maxTimeMS` (int): The maximum amount of time to allow the operation
360+
to run in milliseconds.
361+
- `batchSize` (int): The maximum number of documents to return per
362+
batch. Ignored if the connected mongod or mongos does not support
363+
returning aggregate results using a cursor.
364+
- `collation` (optional): An instance of
365+
:class:`~pymongo.collation.Collation`.
366+
- `let` (dict): A dict of parameter names and values. Values must be
367+
constant or closed expressions that do not reference document
368+
fields. Parameters can then be accessed as variables in an
369+
aggregate expression context (e.g. ``"$$var"``). This option is
370+
only supported on MongoDB >= 5.0.
365371
366372
:Returns:
367373
A :class:`~pymongo.command_cursor.CommandCursor` over the result

0 commit comments

Comments
 (0)