Skip to content

Commit cc68c7c

Browse files
committed
Doc-only changes
1 parent 5f1ee38 commit cc68c7c

File tree

5 files changed

+7
-11
lines changed

5 files changed

+7
-11
lines changed

pymongo/asynchronous/collection.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1776,7 +1776,9 @@ def find(self, *args: Any, **kwargs: Any) -> AsyncCursor[_DocumentType]:
17761776
improper type. Returns an instance of
17771777
:class:`~pymongo.asynchronous.cursor.AsyncCursor` corresponding to this query.
17781778
1779-
Best practice is to call :meth:`AsyncCursor.close` when the cursor is no longer needed,
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,
17801782
or use the cursor in a with statement::
17811783
17821784
async with collection.find() as cursor:

pymongo/asynchronous/cursor.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,14 +1263,10 @@ async def next(self) -> _DocumentType:
12631263
self._exhaust_checked = True
12641264
await self._supports_exhaust()
12651265
if self._empty:
1266-
if self._cursor_type == CursorType.NON_TAILABLE:
1267-
await self.close()
12681266
raise StopAsyncIteration
12691267
if len(self._data) or await self._refresh():
12701268
return self._data.popleft()
12711269
else:
1272-
if self._cursor_type == CursorType.NON_TAILABLE:
1273-
await self.close()
12741270
raise StopAsyncIteration
12751271

12761272
async def _next_batch(self, result: list, total: Optional[int] = None) -> bool: # type: ignore[type-arg]

pymongo/asynchronous/mongo_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def __init__(
205205
Best practice is to call :meth:`AsyncMongoClient.close` when the client is no longer needed,
206206
or use the client in a with statement::
207207
208-
with AsyncMongoClient(url) as client:
208+
async with AsyncMongoClient(url) as client:
209209
# Use client here.
210210
211211
The `host` parameter can be a full `mongodb URI

pymongo/synchronous/collection.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1775,7 +1775,9 @@ def find(self, *args: Any, **kwargs: Any) -> Cursor[_DocumentType]:
17751775
improper type. Returns an instance of
17761776
:class:`~pymongo.cursor.Cursor` corresponding to this query.
17771777
1778-
Best practice is to call :meth:`Cursor.close` when the cursor is no longer needed,
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,
17791781
or use the cursor in a with statement::
17801782
17811783
with collection.find() as cursor:

pymongo/synchronous/cursor.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,14 +1261,10 @@ def next(self) -> _DocumentType:
12611261
self._exhaust_checked = True
12621262
self._supports_exhaust()
12631263
if self._empty:
1264-
if self._cursor_type == CursorType.NON_TAILABLE:
1265-
self.close()
12661264
raise StopIteration
12671265
if len(self._data) or self._refresh():
12681266
return self._data.popleft()
12691267
else:
1270-
if self._cursor_type == CursorType.NON_TAILABLE:
1271-
self.close()
12721268
raise StopIteration
12731269

12741270
def _next_batch(self, result: list, total: Optional[int] = None) -> bool: # type: ignore[type-arg]

0 commit comments

Comments
 (0)