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
:class:`~pymongo.asynchronous.cursor.AsyncCursor` corresponding to this query.
1778
1778
1779
+
Cursors are closed automatically when they are exhausted (the last batch of data is retrieved from the database).
1780
+
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.
1781
+
To avoid this, best practice is to call :meth:`AsyncCursor.close` when the cursor is no longer needed,
1782
+
or use the cursor in a with statement::
1783
+
1784
+
async with collection.find() as cursor:
1785
+
async for doc in cursor:
1786
+
print(doc)
1787
+
1779
1788
The :meth:`find` method obeys the :attr:`read_preference` of
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.
2622
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
+
2623
2650
:param name: If given, the name of the index to search
2624
2651
for. Only indexes with matching index names will be returned.
2625
2652
If not given, all search indexes for the current collection
@@ -2922,6 +2949,15 @@ async def aggregate(
2922
2949
.. note:: The :attr:`~pymongo.asynchronous.collection.AsyncCollection.write_concern` of
2923
2950
this collection is automatically applied to this operation.
2924
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
+
2925
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
+15Lines changed: 15 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -202,6 +202,12 @@ def __init__(
202
202
exception (recognizing that the operation failed) and then continue to
203
203
execute.
204
204
205
+
Best practice is to call :meth:`AsyncMongoClient.close` when the client is no longer needed,
206
+
or use the client in a with statement::
207
+
208
+
async with AsyncMongoClient(url) as client:
209
+
# Use client here.
210
+
205
211
The `host` parameter can be a full `mongodb URI
206
212
<https://dochub.mongodb.org/core/connections>`_, in addition to
207
213
a simple hostname. It can also be a list of hostnames but no more
@@ -2345,6 +2351,15 @@ async def list_databases(
2345
2351
) ->AsyncCommandCursor[dict[str, Any]]:
2346
2352
"""Get a cursor over the databases of the connected server.
2347
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:
:class:`~pymongo.cursor.Cursor` corresponding to this query.
1777
1777
1778
+
Cursors are closed automatically when they are exhausted (the last batch of data is retrieved from the database).
1779
+
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.
1780
+
To avoid this, best practice is to call :meth:`Cursor.close` when the cursor is no longer needed,
1781
+
or use the cursor in a with statement::
1782
+
1783
+
with collection.find() as cursor:
1784
+
for doc in cursor:
1785
+
print(doc)
1786
+
1778
1787
The :meth:`find` method obeys the :attr:`read_preference` of
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
+
2503
2521
:param session: a
2504
2522
:class:`~pymongo.client_session.ClientSession`.
2505
2523
:param comment: A user-provided comment to attach to this
@@ -2617,6 +2635,15 @@ def list_search_indexes(
2617
2635
) ->CommandCursor[Mapping[str, Any]]:
2618
2636
"""Return a cursor over search indexes for the current collection.
2619
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
+
2620
2647
:param name: If given, the name of the index to search
2621
2648
for. Only indexes with matching index names will be returned.
2622
2649
If not given, all search indexes for the current collection
@@ -2915,6 +2942,15 @@ def aggregate(
2915
2942
.. note:: The :attr:`~pymongo.collection.Collection.write_concern` of
2916
2943
this collection is automatically applied to this operation.
2917
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
+
2918
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
+15Lines changed: 15 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -199,6 +199,12 @@ def __init__(
199
199
exception (recognizing that the operation failed) and then continue to
200
200
execute.
201
201
202
+
Best practice is to call :meth:`MongoClient.close` when the client is no longer needed,
203
+
or use the client in a with statement::
204
+
205
+
with MongoClient(url) as client:
206
+
# Use client here.
207
+
202
208
The `host` parameter can be a full `mongodb URI
203
209
<https://dochub.mongodb.org/core/connections>`_, in addition to
204
210
a simple hostname. It can also be a list of hostnames but no more
@@ -2335,6 +2341,15 @@ def list_databases(
2335
2341
) ->CommandCursor[dict[str, Any]]:
2336
2342
"""Get a cursor over the databases of the connected server.
2337
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
+
2338
2353
:param session: a
2339
2354
:class:`~pymongo.client_session.ClientSession`.
2340
2355
:param comment: A user-provided comment to attach to this
0 commit comments