-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathBulk.find.delete.txt
74 lines (49 loc) · 1.63 KB
/
Bulk.find.delete.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
==================
Bulk.find.delete()
==================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
-----------
.. method:: Bulk.find.delete()
Adds a multiple document delete operation to a bulk operations list.
Use the :method:`Bulk.find()` method to specify the condition that
determines which documents to remove.
``Bulk.find.delete()`` deletes all matching documents. To remove the
first matching document, see :method:`Bulk.find.deleteOne()`.
Compatibility
-------------
This command is available in deployments hosted in the following
environments:
.. include:: /includes/fact-environments-atlas-only.rst
.. include:: /includes/fact-environments-atlas-support-all.rst
Syntax
------
The command has the following syntax:
.. code-block:: javascript
Bulk.find( <filter document> ).delete()
For details on the ``find()`` method see: :method:`Bulk.find()`
Example
-------
Create the ``music`` collection:
.. code-block:: javascript
db.music.insertMany( [
{ artist: "DOA", genre: "punk" },
{ artist: "Rick Astley", genre: "pop" },
{ artist: "Black Flag", genre: "punk" },
{ artist: "Justin Bieber", genre: "pop" }
] )
The following example:
- Initializes a :method:`Bulk()` operations builder.
- Searches for the genre ``pop``.
- Deletes ``pop`` music from the collection.
.. code-block:: javascript
var bulk = db.music.initializeOrderedBulkOp();
bulk.find( { "genre": "pop" } ).delete();
bulk.execute()
To delete only the first matching document, use
:method:`Bulk.find.deleteOne()` instead.