Skip to content

Commit

Permalink
MOTOR-936 Mention method delete_one in asyncio tutorial in documentat…
Browse files Browse the repository at this point in the history
…ion (#162)
  • Loading branch information
blink1073 committed Apr 22, 2022
1 parent ca0b27b commit 7822d93
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
20 changes: 19 additions & 1 deletion doc/tutorial-asyncio.rst
Expand Up @@ -342,6 +342,24 @@ update all of them with :meth:`update_many`::
Deleting Documents
------------------

:meth:`~motor.motor_asyncio.AsyncIOMotorCollection.delete_one` takes a query with the same syntax as
:meth:`~motor.motor_asyncio.AsyncIOMotorCollection.find`.
:meth:`delete_one` immediately removes the first returned matching document.

.. doctest:: after-inserting-2000-docs

>>> async def do_delete_one():
... coll = db.test_collection
... n = await coll.count_documents({})
... print('%s documents before calling delete_one()' % n)
... result = await db.test_collection.delete_one({'i': {'$gte': 1000}})
... print('%s documents after' % (await coll.count_documents({})))
...
>>> loop = client.get_io_loop()
>>> loop.run_until_complete(do_delete_one())
2000 documents before calling delete_one()
1999 documents after

:meth:`~motor.motor_asyncio.AsyncIOMotorCollection.delete_many` takes a query with the same syntax as
:meth:`~motor.motor_asyncio.AsyncIOMotorCollection.find`.
:meth:`delete_many` immediately removes all matching documents.
Expand All @@ -357,7 +375,7 @@ Deleting Documents
...
>>> loop = client.get_io_loop()
>>> loop.run_until_complete(do_delete_many())
2000 documents before calling delete_many()
1999 documents before calling delete_many()
1000 documents after

.. mongodoc:: remove
Expand Down
19 changes: 18 additions & 1 deletion doc/tutorial-tornado.rst
Expand Up @@ -428,6 +428,23 @@ update all of them with :meth:`update_many`::
Removing Documents
------------------

:meth:`~MotorCollection.delete_one` takes a query with the same syntax as
:meth:`~MotorCollection.find`.
:meth:`delete_one` immediately removes the first returned matching document.

.. doctest:: after-inserting-2000-docs

>>> async def do_delete_one():
... coll = db.test_collection
... n = await coll.count_documents({})
... print('%s documents before calling delete_one()' % n)
... result = await db.test_collection.delete_one({'i': {'$gte': 1000}})
... print('%s documents after' % (await coll.count_documents({})))
...
>>> IOLoop.current().run_sync(do_delete_one)
2000 documents before calling delete_one()
1999 documents after

:meth:`~MotorCollection.delete_many` takes a query with the same syntax as
:meth:`~MotorCollection.find`.
:meth:`delete_many` immediately removes all matching documents.
Expand All @@ -442,7 +459,7 @@ Removing Documents
... print('%s documents after' % (await coll.count_documents({})))
...
>>> IOLoop.current().run_sync(do_delete_many)
2000 documents before calling delete_many()
1999 documents before calling delete_many()
1000 documents after

.. mongodoc:: remove
Expand Down

0 comments on commit 7822d93

Please sign in to comment.