diff --git a/source/images/compass-delete-button-click.png b/source/images/compass-delete-button-click.png new file mode 100644 index 00000000000..df89f79708c Binary files /dev/null and b/source/images/compass-delete-button-click.png differ diff --git a/source/images/compass-delete-confirm.png b/source/images/compass-delete-confirm.png new file mode 100644 index 00000000000..8a4286b5492 Binary files /dev/null and b/source/images/compass-delete-confirm.png differ diff --git a/source/images/compass-delete-paper-find.png b/source/images/compass-delete-paper-find.png new file mode 100644 index 00000000000..4884adc2e3f Binary files /dev/null and b/source/images/compass-delete-paper-find.png differ diff --git a/source/images/compass-table-btn-click-2.png b/source/images/compass-table-btn-click-2.png new file mode 100644 index 00000000000..5b21341ae1e Binary files /dev/null and b/source/images/compass-table-btn-click-2.png differ diff --git a/source/includes/driver-example-delete-55.rst b/source/includes/driver-example-delete-55.rst index c84a7750875..5ee5fdfde94 100644 --- a/source/includes/driver-example-delete-55.rst +++ b/source/includes/driver-example-delete-55.rst @@ -12,7 +12,7 @@ { item: "paper", qty: 100, size: { h: 8.5, w: 11, uom: "in" }, status: "D" }, { item: "planner", qty: 75, size: { h: 22.85, w: 30, uom: "cm" }, status: "D" }, { item: "postcard", qty: 45, size: { h: 10, w: 15.25, uom: "cm" }, status: "A" }, - ]); + ] ); .. only:: website @@ -20,6 +20,27 @@ .. include:: /includes/fact-mws.rst + - id: compass + content: | + .. code-block:: javascript + + [ + { item: "journal", qty: 25, size: { h: 14, w: 21, uom: "cm" }, status: "A" }, + { item: "notebook", qty: 50, size: { h: 8.5, w: 11, uom: "in" }, status: "P" }, + { item: "paper", qty: 100, size: { h: 8.5, w: 11, uom: "in" }, status: "D" }, + { item: "planner", qty: 75, size: { h: 22.85, w: 30, uom: "cm" }, status: "D" }, + { item: "postcard", qty: 45, size: { h: 10, w: 15.25, uom: "cm" }, status: "A" }, + ] + + For instructions on inserting documents in MongoDB Compass, see + :doc:`Insert Documents `. + + .. note:: + + For complete reference on inserting documents in MongoDB + Compass, see the + :ref:`Compass documentation `. + - id: python content: | .. class:: copyable-code diff --git a/source/includes/driver-example-delete-58.rst b/source/includes/driver-example-delete-58.rst index 293fc484213..1c3c702cd76 100644 --- a/source/includes/driver-example-delete-58.rst +++ b/source/includes/driver-example-delete-58.rst @@ -8,6 +8,65 @@ db.inventory.deleteOne( { status: "D" } ) + - id: compass + content: | + + 1. Click the :guilabel:`Table` button in the top navigation + to access the :ref:`Table View `: + + .. figure:: /images/compass-table-btn-click-2.png + + .. raw:: html + +
+ + #. Use the Compass :ref:`query bar ` to + locate the target document. + + Copy the following filter document into the query bar and click + :guilabel:`Find`: + + .. class:: copyable-code + .. code-block:: javascript + + { item: "paper" } + + .. figure:: /images/compass-delete-paper-find.png + + .. raw:: html + +
+ + #. Hover over the document and click the trash icon which + appears on the right-hand side: + + .. raw:: html + +
+ + .. figure:: /images/compass-delete-button-click.png + + .. raw:: html + +
+ + After clicking the delete button, the document is flagged + for deletion and Compass asks for confirmation that you + want to remove the document: + + .. raw:: html + +
+ + .. figure:: /images/compass-delete-confirm.png + + .. raw:: html + +
+ + #. Click :guilabel:`Delete` to confirm. Compass deletes the + document from the collection. + - id: python content: | .. class:: copyable-code diff --git a/source/includes/fact-delete-all-inventory.rst b/source/includes/fact-delete-all-inventory.rst new file mode 100644 index 00000000000..65ae8001c10 --- /dev/null +++ b/source/includes/fact-delete-all-inventory.rst @@ -0,0 +1,2 @@ +The following example deletes *all* documents from the ``inventory`` +collection: \ No newline at end of file diff --git a/source/includes/fact-delete-condition-inventory.rst b/source/includes/fact-delete-condition-inventory.rst new file mode 100644 index 00000000000..dd726d4f6cb --- /dev/null +++ b/source/includes/fact-delete-condition-inventory.rst @@ -0,0 +1,3 @@ +You can specify criteria, or filters, that identify the documents to +delete. The :ref:`filters ` use the same syntax +as read operations. \ No newline at end of file diff --git a/source/includes/fact-populate-inventory-coll.rst b/source/includes/fact-populate-inventory-coll.rst new file mode 100644 index 00000000000..45f4b20cad6 --- /dev/null +++ b/source/includes/fact-populate-inventory-coll.rst @@ -0,0 +1,2 @@ +The examples on this page use the ``inventory`` collection. To populate +the ``inventory`` collection, run the following: \ No newline at end of file diff --git a/source/includes/fact-remove-condition-inv-example.rst b/source/includes/fact-remove-condition-inv-example.rst new file mode 100644 index 00000000000..a6563a31f75 --- /dev/null +++ b/source/includes/fact-remove-condition-inv-example.rst @@ -0,0 +1,2 @@ +The following example removes all documents from the ``inventory`` +collection where the ``status`` field equals ``"A"``: \ No newline at end of file diff --git a/source/includes/fact-remove-one-condition-inv-example.rst b/source/includes/fact-remove-one-condition-inv-example.rst new file mode 100644 index 00000000000..141ced8a433 --- /dev/null +++ b/source/includes/fact-remove-one-condition-inv-example.rst @@ -0,0 +1,2 @@ +The following example deletes the *first* document where ``status`` is +``"D"``: \ No newline at end of file diff --git a/source/tutorial/remove-documents.txt b/source/tutorial/remove-documents.txt index c99180fd612..52d1c205712 100644 --- a/source/tutorial/remove-documents.txt +++ b/source/tutorial/remove-documents.txt @@ -24,6 +24,17 @@ Delete Documents - :method:`db.collection.deleteMany()` - :method:`db.collection.deleteOne()` + The examples on this page use the ``inventory`` collection. To populate + the ``inventory`` collection, run the following: + + - id: compass + content: | + This page provides examples of deleting documents using + :ref:`MongoDB Compass `. + + Populate the ``inventory`` collection with the following + documents: + - id: python content: | This page provides examples of delete operations using the @@ -33,26 +44,32 @@ Delete Documents - :py:meth:`pymongo.collection.Collection.delete_many` - :py:meth:`pymongo.collection.Collection.delete_one` + .. include:: /includes/fact-populate-inventory-coll.rst + - id: java-sync content: | - This page provides examples of delete operations using the - following methods in the `Java Synchronous Driver`_: + This page provides examples of delete operations using the + following methods in the `Java Synchronous Driver`_: - - com.mongodb.client.MongoCollection.deleteMany_ + - com.mongodb.client.MongoCollection.deleteMany_ - - com.mongodb.client.MongoCollection.deleteOne_ + - com.mongodb.client.MongoCollection.deleteOne_ + + .. include:: /includes/fact-populate-inventory-coll.rst - id: java-async content: | - This page provides examples of delete operations using the - following methods in the `Java Reactive Streams Driver - `_: + This page provides examples of delete operations using the + following methods in the `Java Reactive Streams Driver + `_: - - `com.mongodb.reactivestreams.client.MongoCollection.deleteMany - `_ + - `com.mongodb.reactivestreams.client.MongoCollection.deleteMany + `_ - - `com.mongodb.reactivestreams.client.MongoCollection.deleteOne - `_ + - `com.mongodb.reactivestreams.client.MongoCollection.deleteOne + `_ + + .. include:: /includes/fact-populate-inventory-coll.rst - id: nodejs content: | @@ -63,6 +80,8 @@ Delete Documents - :node-api:`Collection.deleteMany() ` - :node-api:`Collection.deleteOne() ` + .. include:: /includes/fact-populate-inventory-coll.rst + - id: php content: | This page provides examples of delete operations using the @@ -72,6 +91,8 @@ Delete Documents - :phpmethod:`MongoDB\\Collection::deleteMany() ` - :phpmethod:`MongoDB\\Collection::deleteOne() ` + .. include:: /includes/fact-populate-inventory-coll.rst + - id: perl content: | This page provides examples of delete operations using the @@ -81,6 +102,8 @@ Delete Documents - :perl-api:`MongoDB::Collection::delete_many()` - :perl-api:`MongoDB::Collection::delete_one()` + .. include:: /includes/fact-populate-inventory-coll.rst + - id: ruby content: | This page provides examples of delete operations using the @@ -90,16 +113,20 @@ Delete Documents - :ruby-api:`Mongo::Collection#delete_many()` - :ruby-api:`Mongo::Collection#delete_one()` + .. include:: /includes/fact-populate-inventory-coll.rst + - id: scala content: | This page provides examples of delete operations using the following methods in the `MongoDB Scala Driver `_: - + - :scala-api:`collection.deleteMany()` - + - :scala-api:`collection.deleteOne()` + .. include:: /includes/fact-populate-inventory-coll.rst + - id: csharp content: | This page provides examples of delete operations using the @@ -109,266 +136,479 @@ Delete Documents - :csharp-api:`IMongoCollection.DeleteMany() ` - :csharp-api:`IMongoCollection.DeleteOne() ` -The examples on this page use the ``inventory`` collection. To populate -the ``inventory`` collection, run the following: + .. include:: /includes/fact-populate-inventory-coll.rst .. include:: /includes/driver-example-delete-55.rst .. _write-op-deleteMany: -Delete All Documents --------------------- - .. tabs-drivers:: tabs: - id: shell content: | - To remove all documents from a collection, pass an empty + .. raw:: html + +
+ + Delete All Documents + -------------------- + + To delete all documents from a collection, pass an empty :ref:`filter` document ``{}`` to the :method:`db.collection.deleteMany()` method. + .. include:: /includes/fact-delete-all-inventory.rst + - id: python content: | - To remove all documents from a collection, pass an empty + Delete All Documents + -------------------- + + To delete all documents from a collection, pass an empty :ref:`filter` document ``{}`` to the :py:meth:`pymongo.collection.Collection.delete_many` method. + .. include:: /includes/fact-delete-all-inventory.rst + - id: java-sync content: | - To remove all documents from a collection, pass an empty + Delete All Documents + -------------------- + + To delete all documents from a collection, pass an empty org.bson.Document_ object as the :ref:`filter` to the com.mongodb.client.MongoCollection.deleteMany_ method. + .. include:: /includes/fact-delete-all-inventory.rst + - id: java-async content: | - To remove all documents from a collection, pass an empty + Delete All Documents + -------------------- + + To delete all documents from a collection, pass an empty org.bson.Document_ object as the :ref:`filter` to the `com.mongodb.reactivestreams.client.MongoCollection.deleteMany `_ method. + .. include:: /includes/fact-delete-all-inventory.rst + - id: nodejs content: | - To remove all documents from a collection, pass an empty + Delete All Documents + -------------------- + + To delete all documents from a collection, pass an empty :ref:`filter` document ``{}`` to the :node-api:`Collection.deleteMany() ` method. + .. include:: /includes/fact-delete-all-inventory.rst + - id: php content: | - To remove all documents from a collection, pass an empty + Delete All Documents + -------------------- + + To delete all documents from a collection, pass an empty :ref:`filter` document ``[]`` to the :phpmethod:`MongoDB\\Collection::deleteMany() ` method. + .. include:: /includes/fact-delete-all-inventory.rst + - id: perl content: | - To remove all documents from a collection, pass an empty + Delete All Documents + -------------------- + + To delete all documents from a collection, pass an empty :ref:`filter` document ``{}`` to the :perl-api:`MongoDB::Collection::delete_many()` method. + .. include:: /includes/fact-delete-all-inventory.rst + - id: ruby content: | - To remove all documents from a collection, pass an empty + Delete All Documents + -------------------- + + To delete all documents from a collection, pass an empty :ref:`filter` document ``{}`` to the :ruby-api:`Mongo::Collection#delete_many()` method. + .. include:: /includes/fact-delete-all-inventory.rst + - id: scala content: | - To remove all documents from a collection, pass an empty + Delete All Documents + -------------------- + + To delete all documents from a collection, pass an empty :ref:`filter` ``Document()`` to the :scala-api:`collection.deleteMany()` method. + .. include:: /includes/fact-delete-all-inventory.rst + - id: csharp content: | - To remove all documents from a collection, pass an empty + Delete All Documents + -------------------- + + To delete all documents from a collection, pass an empty :ref:`filter` ``Builders.Filter.Empty`` to the :csharp-api:`IMongoCollection.DeleteMany() ` method. -The following example deletes *all* documents from the ``inventory`` -collection: + .. include:: /includes/fact-delete-all-inventory.rst .. include:: /includes/driver-example-delete-56.rst .. include:: /includes/driver-example-delete-result.rst -Delete All Documents that Match a Condition -------------------------------------------- - -You can specify criteria, or filters, that identify the documents to -delete. The :ref:`filters ` use the same syntax -as read operations. - -.. include:: /includes/extracts/filter-equality.rst - -.. include:: /includes/extracts/filter-query-operators.rst - .. tabs-drivers:: tabs: - id: shell content: | + Delete All Documents that Match a Condition + ------------------------------------------- + + .. include:: /includes/fact-delete-condition-inventory.rst + + .. include:: /includes/extracts/filter-equality.rst + + .. include:: /includes/extracts/filter-query-operators.rst + To delete all documents that match a deletion criteria, pass a :ref:`filter ` parameter to the :method:`~db.collection.deleteMany()` method. + .. include:: /includes/fact-remove-condition-inv-example.rst + - id: python content: | + Delete All Documents that Match a Condition + ------------------------------------------- + + .. include:: /includes/fact-delete-condition-inventory.rst + + .. include:: /includes/extracts/filter-equality.rst + + .. include:: /includes/extracts/filter-query-operators.rst + To delete all documents that match a deletion criteria, pass a :ref:`filter ` parameter to the :py:meth:`~pymongo.collection.Collection.delete_many` method. + .. include:: /includes/fact-remove-condition-inv-example.rst + - id: java-sync content: | + Delete All Documents that Match a Condition + ------------------------------------------- + + .. include:: /includes/fact-delete-condition-inventory.rst + + .. include:: /includes/extracts/filter-equality.rst + + .. include:: /includes/extracts/filter-query-operators.rst + To delete all documents that match a deletion criteria, pass a :ref:`filter ` parameter to the com.mongodb.client.MongoCollection.deleteMany_ method. + .. include:: /includes/fact-remove-condition-inv-example.rst + - id: java-async content: | + Delete All Documents that Match a Condition + ------------------------------------------- + + .. include:: /includes/fact-delete-condition-inventory.rst + + .. include:: /includes/extracts/filter-equality.rst + + .. include:: /includes/extracts/filter-query-operators.rst + To delete all documents that match a deletion criteria, pass a :ref:`filter ` parameter to the `com.mongodb.reactivestreams.client.MongoCollection.deleteMany `_ method. + .. include:: /includes/fact-remove-condition-inv-example.rst + - id: nodejs content: | + Delete All Documents that Match a Condition + ------------------------------------------- + + .. include:: /includes/fact-delete-condition-inventory.rst + + .. include:: /includes/extracts/filter-equality.rst + + .. include:: /includes/extracts/filter-query-operators.rst + To delete all documents that match a deletion criteria, pass a :ref:`filter ` parameter to the :node-api:`deleteMany() ` method. + .. include:: /includes/fact-remove-condition-inv-example.rst + - id: php content: | + Delete All Documents that Match a Condition + ------------------------------------------- + + .. include:: /includes/fact-delete-condition-inventory.rst + + .. include:: /includes/extracts/filter-equality.rst + + .. include:: /includes/extracts/filter-query-operators.rst + To delete all documents that match a deletion criteria, pass a :ref:`filter ` parameter to the :phpmethod:`deleteMany() ` method. + .. include:: /includes/fact-remove-condition-inv-example.rst + - id: perl content: | + Delete All Documents that Match a Condition + ------------------------------------------- + + .. include:: /includes/fact-delete-condition-inventory.rst + + .. include:: /includes/extracts/filter-equality.rst + + .. include:: /includes/extracts/filter-query-operators.rst + To delete all documents that match a deletion criteria, pass a :ref:`filter ` parameter to the :perl-api:`delete_many()` method. + .. include:: /includes/fact-remove-condition-inv-example.rst + - id: ruby content: | + Delete All Documents that Match a Condition + ------------------------------------------- + + .. include:: /includes/fact-delete-condition-inventory.rst + + .. include:: /includes/extracts/filter-equality.rst + + .. include:: /includes/extracts/filter-query-operators.rst + To delete all documents that match a deletion criteria, pass a :ref:`filter ` parameter to the :ruby-api:`delete_many()` method. + .. include:: /includes/fact-remove-condition-inv-example.rst + - id: scala content: | + Delete All Documents that Match a Condition + ------------------------------------------- + + .. include:: /includes/fact-delete-condition-inventory.rst + + .. include:: /includes/extracts/filter-equality.rst + + .. include:: /includes/extracts/filter-query-operators.rst + To delete all documents that match a deletion criteria, pass a :ref:`filter ` parameter to the :scala-api:`deleteMany()` method. + .. include:: /includes/fact-remove-condition-inv-example.rst + - id: csharp content: | + Delete All Documents that Match a Condition + ------------------------------------------- + + .. include:: /includes/fact-delete-condition-inventory.rst + + .. include:: /includes/extracts/filter-equality.rst + + .. include:: /includes/extracts/filter-query-operators.rst + To delete all documents that match a deletion criteria, pass a :ref:`filter ` parameter to the :csharp-api:`IMongoCollection.DeleteMany() ` method. -The following example removes all documents from the ``inventory`` -collection where the ``status`` field equals ``"A"``: + .. include:: /includes/fact-remove-condition-inv-example.rst .. include:: /includes/driver-example-delete-57.rst .. include:: /includes/driver-example-delete-result.rst -Remove Only One Document that Matches a Condition -------------------------------------------------- - .. tabs-drivers:: tabs: - id: shell content: | + Delete Only One Document that Matches a Condition + ------------------------------------------------- + To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the :method:`db.collection.deleteOne()` method. + .. include:: /includes/fact-remove-one-condition-inv-example.rst + + - id: compass + content: | + Delete a Single Document + ------------------------ + + MongoDB Compass provides a simple way to delete a document + from a collection. The following example shows how to delete + the document with ``item`` equal to ``paper`` from the + ``inventory`` collection: + + .. note:: + + In this example we are using the Compass + :ref:`Table View ` to delete the + document. The deletion process using the Compass + :ref:`List View ` follows a very + similar approach. + + For more information on the differences between Table View + and List View in Compass, refer to the + :ref:`Compass documentation `. + - id: python content: | + Delete Only One Document that Matches a Condition + ------------------------------------------------- + To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the :py:meth:`pymongo.collection.Collection.delete_one` method. + .. include:: /includes/fact-remove-one-condition-inv-example.rst + - id: java-sync content: | + Delete Only One Document that Matches a Condition + ------------------------------------------------- + To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the com.mongodb.client.MongoCollection.deleteOne_ method. + .. include:: /includes/fact-remove-one-condition-inv-example.rst + - id: java-async content: | + Delete Only One Document that Matches a Condition + ------------------------------------------------- + To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the `com.mongodb.reactivestreams.client.MongoCollection.deleteMany `_ method. + .. include:: /includes/fact-remove-one-condition-inv-example.rst + - id: nodejs content: | + Delete Only One Document that Matches a Condition + ------------------------------------------------- + To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the :node-api:`Collection.deleteOne() ` method. + .. include:: /includes/fact-remove-one-condition-inv-example.rst + - id: php content: | + Delete Only One Document that Matches a Condition + ------------------------------------------------- + To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the :phpmethod:`MongoDB\\Collection::deleteOne() ` method. + .. include:: /includes/fact-remove-one-condition-inv-example.rst + - id: perl content: | + Delete Only One Document that Matches a Condition + ------------------------------------------------- + To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the - :perl-api:`MongoDB::Collection::delete_one()` method. + :perl-api:`MongoDB::Collection::delete_one()` + method. + + .. include:: /includes/fact-remove-one-condition-inv-example.rst - id: ruby content: | + Delete Only One Document that Matches a Condition + ------------------------------------------------- + To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the - :ruby-api:`Mongo::Collection#delete_one()` method. + :ruby-api:`Mongo::Collection#delete_one()` + method. + + .. include:: /includes/fact-remove-one-condition-inv-example.rst - id: csharp content: | + Delete Only One Document that Matches a Condition + ------------------------------------------------- + To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the :csharp-api:`IMongoCollection.DeleteOne() ` + method. + + .. include:: /includes/fact-remove-one-condition-inv-example.rst - id: scala content: | + Delete Only One Document that Matches a Condition + ------------------------------------------------- + To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the - :scala-api:`collection.deleteOne()` method. + :scala-api:`collection.deleteOne()` + method. -The following example deletes the *first* document where ``status`` is -``"D"``. + .. include:: /includes/fact-remove-one-condition-inv-example.rst .. include:: /includes/driver-example-delete-58.rst @@ -411,6 +651,14 @@ requested from MongoDB for write operations. For details, see - :ref:`additional-deletes` + - id: compass + content: | + .. seealso:: + + - `Compass Documents `_ + + - :ref:`Compass Query Bar ` + - id: python content: | .. seealso:: @@ -485,9 +733,9 @@ requested from MongoDB for write operations. For details, see - id: scala content: | .. seealso:: - + - :scala-api:`collection.deleteMany()` - + - :scala-api:`collection.deleteOne()` - :ref:`additional-deletes`