You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cursors are closed automatically when they are exhausted (the last batch of data is retrieved from the database).
2516
+
If a cursor is not exhausted, it will be closed automatically upon garbage collection, which leaves resources open but unused for a potentially long period of time.
2517
+
To avoid this, best practice is to call :meth:`AsyncCursor.close` when the cursor is no longer needed,
2518
+
or use the cursor in a with statement::
2519
+
2520
+
async with await collection.list_indexes() as cursor:
"""Return a cursor over search indexes for the current collection.
2631
2640
2641
+
Cursors are closed automatically when they are exhausted (the last batch of data is retrieved from the database).
2642
+
If a cursor is not exhausted, it will be closed automatically upon garbage collection, which leaves resources open but unused for a potentially long period of time.
2643
+
To avoid this, best practice is to call :meth:`AsyncCursor.close` when the cursor is no longer needed,
2644
+
or use the cursor in a with statement::
2645
+
2646
+
async with await collection.list_search_indexes() as cursor:
2647
+
async for index in cursor:
2648
+
print(index)
2649
+
2632
2650
:param name: If given, the name of the index to search
2633
2651
for. Only indexes with matching index names will be returned.
2634
2652
If not given, all search indexes for the current collection
@@ -2931,6 +2949,15 @@ async def aggregate(
2931
2949
.. note:: The :attr:`~pymongo.asynchronous.collection.AsyncCollection.write_concern` of
2932
2950
this collection is automatically applied to this operation.
2933
2951
2952
+
Cursors are closed automatically when they are exhausted (the last batch of data is retrieved from the database).
2953
+
If a cursor is not exhausted, it will be closed automatically upon garbage collection, which leaves resources open but unused for a potentially long period of time.
2954
+
To avoid this, best practice is to call :meth:`AsyncCursor.close` when the cursor is no longer needed,
2955
+
or use the cursor in a with statement::
2956
+
2957
+
async with await collection.aggregate() as cursor:
2958
+
async for operation in cursor:
2959
+
print(operation)
2960
+
2934
2961
:param pipeline: a list of aggregation pipeline stages
Copy file name to clipboardExpand all lines: pymongo/asynchronous/database.py
+16-2Lines changed: 16 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -643,15 +643,20 @@ async def aggregate(
643
643
.. code-block:: python
644
644
645
645
# Lists all operations currently running on the server.
646
-
with client.admin.aggregate([{"$currentOp": {}}]) as cursor:
647
-
for operation in cursor:
646
+
async with await client.admin.aggregate([{"$currentOp": {}}]) as cursor:
647
+
async for operation in cursor:
648
648
print(operation)
649
649
650
650
The :meth:`aggregate` method obeys the :attr:`read_preference` of this
651
651
:class:`AsyncDatabase`, except when ``$out`` or ``$merge`` are used, in
652
652
which case :attr:`~pymongo.read_preferences.ReadPreference.PRIMARY`
653
653
is used.
654
654
655
+
Cursors are closed automatically when they are exhausted (the last batch of data is retrieved from the database).
656
+
If a cursor is not exhausted, it will be closed automatically upon garbage collection, which leaves resources open but unused for a potentially long period of time.
657
+
To avoid this, best practice is to call :meth:`AsyncCursor.close` when the cursor is no longer needed,
658
+
or use the cursor in a with statement.
659
+
655
660
.. note:: This method does not support the 'explain' option. Please
656
661
use :meth:`~pymongo.asynchronous.database.AsyncDatabase.command` instead.
"""Get a cursor over the collections of this database.
1156
1161
1162
+
Cursors are closed automatically when they are exhausted (the last batch of data is retrieved from the database).
1163
+
If a cursor is not exhausted, it will be closed automatically upon garbage collection, which leaves resources open but unused for a potentially long period of time.
1164
+
To avoid this, best practice is to call :meth:`AsyncCursor.close` when the cursor is no longer needed,
1165
+
or use the cursor in a with statement::
1166
+
1167
+
async with await database.list_collections() as cursor:
Copy file name to clipboardExpand all lines: pymongo/asynchronous/mongo_client.py
+9Lines changed: 9 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2351,6 +2351,15 @@ async def list_databases(
2351
2351
) ->AsyncCommandCursor[dict[str, Any]]:
2352
2352
"""Get a cursor over the databases of the connected server.
2353
2353
2354
+
Cursors are closed automatically when they are exhausted (the last batch of data is retrieved from the database).
2355
+
If a cursor is not exhausted, it will be closed automatically upon garbage collection, which leaves resources open but unused for a potentially long period of time.
2356
+
To avoid this, best practice is to call :meth:`AsyncCursor.close` when the cursor is no longer needed,
2357
+
or use the cursor in a with statement::
2358
+
2359
+
async with await client.list_databases() as cursor:
Cursors are closed automatically when they are exhausted (the last batch of data is retrieved from the database).
2513
+
If a cursor is not exhausted, it will be closed automatically upon garbage collection, which leaves resources open but unused for a potentially long period of time.
2514
+
To avoid this, best practice is to call :meth:`Cursor.close` when the cursor is no longer needed,
2515
+
or use the cursor in a with statement::
2516
+
2517
+
with collection.list_indexes() as cursor:
2518
+
for index in cursor:
2519
+
print(index)
2520
+
2512
2521
:param session: a
2513
2522
:class:`~pymongo.client_session.ClientSession`.
2514
2523
:param comment: A user-provided comment to attach to this
@@ -2626,6 +2635,15 @@ def list_search_indexes(
2626
2635
) ->CommandCursor[Mapping[str, Any]]:
2627
2636
"""Return a cursor over search indexes for the current collection.
2628
2637
2638
+
Cursors are closed automatically when they are exhausted (the last batch of data is retrieved from the database).
2639
+
If a cursor is not exhausted, it will be closed automatically upon garbage collection, which leaves resources open but unused for a potentially long period of time.
2640
+
To avoid this, best practice is to call :meth:`Cursor.close` when the cursor is no longer needed,
2641
+
or use the cursor in a with statement::
2642
+
2643
+
with collection.list_search_indexes() as cursor:
2644
+
for index in cursor:
2645
+
print(index)
2646
+
2629
2647
:param name: If given, the name of the index to search
2630
2648
for. Only indexes with matching index names will be returned.
2631
2649
If not given, all search indexes for the current collection
@@ -2924,6 +2942,15 @@ def aggregate(
2924
2942
.. note:: The :attr:`~pymongo.collection.Collection.write_concern` of
2925
2943
this collection is automatically applied to this operation.
2926
2944
2945
+
Cursors are closed automatically when they are exhausted (the last batch of data is retrieved from the database).
2946
+
If a cursor is not exhausted, it will be closed automatically upon garbage collection, which leaves resources open but unused for a potentially long period of time.
2947
+
To avoid this, best practice is to call :meth:`Cursor.close` when the cursor is no longer needed,
2948
+
or use the cursor in a with statement::
2949
+
2950
+
with collection.aggregate() as cursor:
2951
+
for operation in cursor:
2952
+
print(operation)
2953
+
2927
2954
:param pipeline: a list of aggregation pipeline stages
Copy file name to clipboardExpand all lines: pymongo/synchronous/database.py
+14Lines changed: 14 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -652,6 +652,11 @@ def aggregate(
652
652
which case :attr:`~pymongo.read_preferences.ReadPreference.PRIMARY`
653
653
is used.
654
654
655
+
Cursors are closed automatically when they are exhausted (the last batch of data is retrieved from the database).
656
+
If a cursor is not exhausted, it will be closed automatically upon garbage collection, which leaves resources open but unused for a potentially long period of time.
657
+
To avoid this, best practice is to call :meth:`Cursor.close` when the cursor is no longer needed,
658
+
or use the cursor in a with statement.
659
+
655
660
.. note:: This method does not support the 'explain' option. Please
656
661
use :meth:`~pymongo.database.Database.command` instead.
657
662
@@ -1148,6 +1153,15 @@ def list_collections(
1148
1153
) ->CommandCursor[MutableMapping[str, Any]]:
1149
1154
"""Get a cursor over the collections of this database.
1150
1155
1156
+
Cursors are closed automatically when they are exhausted (the last batch of data is retrieved from the database).
1157
+
If a cursor is not exhausted, it will be closed automatically upon garbage collection, which leaves resources open but unused for a potentially long period of time.
1158
+
To avoid this, best practice is to call :meth:`Cursor.close` when the cursor is no longer needed,
1159
+
or use the cursor in a with statement::
1160
+
1161
+
with database.list_collections() as cursor:
1162
+
for collection in cursor:
1163
+
print(collection)
1164
+
1151
1165
:param session: a
1152
1166
:class:`~pymongo.client_session.ClientSession`.
1153
1167
:param filter: A query document to filter the list of
Copy file name to clipboardExpand all lines: pymongo/synchronous/mongo_client.py
+9Lines changed: 9 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2341,6 +2341,15 @@ def list_databases(
2341
2341
) ->CommandCursor[dict[str, Any]]:
2342
2342
"""Get a cursor over the databases of the connected server.
2343
2343
2344
+
Cursors are closed automatically when they are exhausted (the last batch of data is retrieved from the database).
2345
+
If a cursor is not exhausted, it will be closed automatically upon garbage collection, which leaves resources open but unused for a potentially long period of time.
2346
+
To avoid this, best practice is to call :meth:`Cursor.close` when the cursor is no longer needed,
2347
+
or use the cursor in a with statement::
2348
+
2349
+
with client.list_databases() as cursor:
2350
+
for database in cursor:
2351
+
print(database)
2352
+
2344
2353
:param session: a
2345
2354
:class:`~pymongo.client_session.ClientSession`.
2346
2355
:param comment: A user-provided comment to attach to this
0 commit comments