Skip to content

Commit 48b0d63

Browse files
author
Dave Cuthbert
authored
DOCSP-15952 BACKPORT (#1117)
1 parent 4650f92 commit 48b0d63

12 files changed

+246
-76
lines changed

source/core/bulk-write-operations.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ acknowledgement required for bulk write operations.
2121
.. versionadded:: 3.2
2222

2323
The :method:`db.collection.bulkWrite()` method provides the ability to
24-
perform bulk insert, update, and remove operations.
25-
MongoDB also supports bulk insert
26-
through the :method:`db.collection.insertMany()`.
24+
perform bulk insert, update, and delete operations.
25+
26+
MongoDB also supports bulk insert through the
27+
:method:`db.collection.insertMany()` method.
2728

2829
Ordered vs Unordered Operations
2930
-------------------------------

source/reference/method.txt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -656,17 +656,21 @@ Bulk Write Operation
656656

657657
- Specifies the :ref:`collation <collation>` for the query condition.
658658

659+
* - :method:`Bulk.find.delete()`
660+
- Adds a multiple document delete operation to a list of operations.
661+
662+
* - :method:`Bulk.find.deleteOne()`
663+
- Adds a single document delete operation to a list of operations.
664+
659665
* - :method:`Bulk.find.hint()`
660666

661667
- Specifies the index to use for the update/replace operation.
662668

663669
* - :method:`Bulk.find.remove()`
664-
665-
- Adds a multiple document remove operation to a list of operations.
670+
- An alias for ``Bulk.find.delete()``.
666671

667672
* - :method:`Bulk.find.removeOne()`
668-
669-
- Adds a single document remove operation to a list of operations.
673+
- An alias for ``Bulk.find.deleteOne()``.
670674

671675
* - :method:`Bulk.find.replaceOne()`
672676

@@ -692,13 +696,11 @@ Bulk Write Operation
692696

693697
- Adds an insert operation to a list of operations.
694698

695-
* - :method:`Bulk.tojson()`
696-
699+
* - :method:`Bulk.toJSON()`
697700
- Returns a JSON document that contains the number of operations and batches in the :method:`Bulk()` operations object.
698701

699702
* - :method:`Bulk.toString()`
700-
701-
- Returns the :method:`Bulk.tojson()` results as a string.
703+
- Returns the :method:`Bulk.toJSON()` results as a string.
702704

703705

704706
.. toctree::
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
==================
2+
Bulk.find.delete()
3+
==================
4+
5+
.. default-domain:: mongodb
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 1
11+
:class: singlecol
12+
13+
Definition
14+
-----------
15+
16+
.. method:: Bulk.find.delete()
17+
18+
Adds a multiple document delete operation to a bulk operations list.
19+
Use the :method:`Bulk.find()` method to specify the condition that
20+
determines which documents to remove.
21+
22+
``Bulk.find.delete()`` deletes all matching documents. To remove the
23+
first matching document, see :method:`Bulk.find.deleteOne()`.
24+
25+
Syntax
26+
------
27+
28+
The command has the following syntax:
29+
30+
.. code-block:: javascript
31+
32+
Bulk.find( <filter document> ).delete()
33+
34+
For details on the ``find()`` method see: :method:`Bulk.find()`
35+
36+
Example
37+
-------
38+
39+
Create the ``music`` collection:
40+
41+
.. code-block:: javascript
42+
43+
db.music.insertMany( [
44+
{ artist: "DOA", genre: "punk" },
45+
{ artist: "Rick Astley", genre: "pop" },
46+
{ artist: "Black Flag", genre: "punk" },
47+
{ artist: "Justin Bieber", genre: "pop" }
48+
] )
49+
50+
The following example:
51+
52+
- Initializes a :method:`Bulk()` operations builder.
53+
- Searches for the genre ``pop``.
54+
- Deletes ``pop`` music from the collection.
55+
56+
.. code-block:: javascript
57+
58+
var bulk = db.music.initializeOrderedBulkOp();
59+
bulk.find( { "genre": "pop" } ).delete();
60+
bulk.execute()
61+
62+
To delete only the first matching document, use
63+
:method:`Bulk.find.deleteOne()` instead.
64+
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
=====================
2+
Bulk.find.deleteOne()
3+
=====================
4+
5+
.. default-domain:: mongodb
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 1
11+
:class: singlecol
12+
13+
Definition
14+
-----------
15+
16+
.. method:: Bulk.find.deleteOne()
17+
18+
Adds a single document remove operation to a bulk operations list.
19+
Use the :method:`Bulk.find()` method to specify the condition that
20+
determines which document to remove.
21+
22+
``Bulk.find.deleteOne()`` only deletes the first matching document.
23+
To remove multiple documents, see :method:`Bulk.find.delete()`.
24+
25+
Syntax
26+
------
27+
28+
The command has the following syntax:
29+
30+
.. code-block:: javascript
31+
32+
Bulk.find( <filter document> ).deleteOne()
33+
34+
For details on the ``find()`` method see: :method:`Bulk.find()`
35+
36+
Example
37+
-------
38+
39+
Create the ``music`` collection:
40+
41+
.. code-block:: javascript
42+
43+
db.music.insertMany( [
44+
{ artist: "DOA", genre: "punk" },
45+
{ artist: "Rick Astley", genre: "pop" },
46+
{ artist: "Black Flag", genre: "punk" },
47+
{ artist: "Justin Bieber", genre: "pop" }
48+
] )
49+
50+
The following example:
51+
52+
- Initializes a :method:`Bulk()` operations builder.
53+
- Searches for the genre ``pop``.
54+
- Deletes ``Rick Astley``, the first matching pop artist, from the
55+
collection.
56+
57+
.. code-block:: javascript
58+
59+
var bulk = db.music.initializeOrderedBulkOp();
60+
bulk.find( { "genre": "pop" } ).deleteOne();
61+
bulk.execute()
62+
63+
To delete all ``"pop"`` music, use :method:`Bulk.find.delete()` instead.
64+

source/reference/method/Bulk.find.remove.txt

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,35 @@ Description
1717

1818
.. method:: Bulk.find.remove()
1919

20-
Adds a remove operation to a bulk operations list. Use the
21-
:method:`Bulk.find()` method to specify the condition that
22-
determines which documents to remove. The
23-
:method:`Bulk.find.remove()` method removes all matching documents
24-
in the collection. To limit the remove to a single document, see
25-
:method:`Bulk.find.removeOne()`.
20+
Starting in ``mongosh`` 0.12.2, ``Bulk.find.remove()`` is an alias
21+
for :method:`Bulk.find.delete()`.
22+
23+
In new code, use ``Bulk.find.delete()`` instead of
24+
``Bulk.find.remove()``.
2625

2726
Example
2827
-------
2928

30-
The following example initializes a :method:`Bulk()` operations builder
31-
for the ``items`` collection and adds a remove operation to the list of
32-
operations. The remove operation removes all documents in the
33-
collection where the ``status`` equals ``"D"``:
29+
Create the ``music`` collection:
3430

3531
.. code-block:: javascript
3632

37-
var bulk = db.items.initializeUnorderedBulkOp();
38-
bulk.find( { status: "D" } ).remove();
39-
bulk.execute();
33+
db.music.insertMany( [
34+
{ artist: "DOA", genre: "punk" },
35+
{ artist: "Rick Astley", genre: "pop" },
36+
{ artist: "Black Flag", genre: "punk" },
37+
{ artist: "Justin Bieber", genre: "pop" }
38+
] )
39+
40+
The following example:
41+
42+
- Initializes a :method:`Bulk()` operations builder.
43+
- Searches for the genre ``pop``.
44+
- Deletes ``pop`` music from the collection.
45+
46+
.. code-block:: javascript
4047

41-
.. seealso::
48+
var bulk = db.music.initializeOrderedBulkOp();
49+
bulk.find( { "genre": "pop" } ).remove();
50+
bulk.execute()
4251

43-
- :method:`db.collection.initializeUnorderedBulkOp()`
44-
- :method:`db.collection.initializeOrderedBulkOp()`
45-
- :method:`Bulk.find()`
46-
- :method:`Bulk.find.removeOne()`
47-
- :method:`Bulk.execute()`

source/reference/method/Bulk.find.removeOne.txt

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,37 @@ Description
1717

1818
.. method:: Bulk.find.removeOne()
1919

20-
Adds a single document remove operation to a bulk operations list.
21-
Use the :method:`Bulk.find()` method to specify the condition that
22-
determines which document to remove. The
23-
:method:`Bulk.find.removeOne()` limits the removal to one document.
24-
To remove multiple documents, see :method:`Bulk.find.remove()`.
20+
21+
Starting in ``mongosh`` 0.12.2, ``Bulk.find.removeOne()`` is an alias
22+
for :method:`Bulk.find.deleteOne()`.
23+
24+
In new code, use ``Bulk.find.deleteOne()`` instead of
25+
``Bulk.find.removeOne()``.
2526

2627
Example
2728
-------
2829

29-
The following example initializes a :method:`Bulk()` operations builder
30-
for the ``items`` collection and adds two
31-
:method:`Bulk.find.removeOne()` operations to the list of operations.
32-
33-
Each remove operation removes just one document: one document with the
34-
``status`` equal to ``"D"`` and another document with the ``status``
35-
equal to ``"P"``.
30+
Create the ``music`` collection:
3631

3732
.. code-block:: javascript
3833

39-
var bulk = db.items.initializeUnorderedBulkOp();
40-
bulk.find( { status: "D" } ).removeOne();
41-
bulk.find( { status: "P" } ).removeOne();
42-
bulk.execute();
34+
db.music.insertMany( [
35+
{ artist: "DOA", genre: "punk" },
36+
{ artist: "Rick Astley", genre: "pop" },
37+
{ artist: "Black Flag", genre: "punk" },
38+
{ artist: "Justin Bieber", genre: "pop" }
39+
] )
40+
41+
The following example:
42+
43+
- Initializes a :method:`Bulk()` operations builder.
44+
- Searches for the genre ``pop``.
45+
- Deletes ``Rick Astley``, the first matching pop artist, from the
46+
collection.
47+
48+
.. code-block:: javascript
4349

44-
.. seealso::
50+
var bulk = db.music.initializeOrderedBulkOp();
51+
bulk.find( { "genre": "pop" } ).removeOne();
52+
bulk.execute()
4553

46-
- :method:`db.collection.initializeUnorderedBulkOp()`
47-
- :method:`db.collection.initializeOrderedBulkOp()`
48-
- :method:`Bulk.find()`
49-
- :method:`Bulk.find.remove()`
50-
- :method:`Bulk.execute()`
51-
- :ref:`All Bulk Methods <bulk-methods>`

source/reference/method/Bulk.find.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ condition for their respective actions:
7575
.. code-block:: javascript
7676

7777
var bulk = db.items.initializeUnorderedBulkOp();
78-
bulk.find( { status: "D" } ).remove();
78+
bulk.find( { status: "D" } ).delete();
7979
bulk.find( { status: "P" } ).update( { $set: { points: 0 } } )
8080
bulk.execute();
8181

source/reference/method/Bulk.toString.txt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,27 @@ The following initializes a :method:`Bulk()` operations builder on the
2727
var bulk = db.items.initializeOrderedBulkOp();
2828
bulk.insert( { item: "abc123", status: "A", defaultQty: 500, points: 5 } );
2929
bulk.insert( { item: "ijk123", status: "A", defaultQty: 100, points: 10 } );
30-
bulk.find( { status: "D" } ).removeOne();
30+
bulk.find( { status: "D" } ).deleteOne();
3131
bulk.toString();
32+
bulk.execute()
3233

3334
The :method:`Bulk.toString()` returns the following JSON document
3435

3536
.. code-block:: javascript
36-
37-
{ "nInsertOps" : 2, "nUpdateOps" : 0, "nRemoveOps" : 1, "nBatches" : 2 }
37+
38+
{
39+
acknowledged: true,
40+
insertedCount: 2,
41+
insertedIds: [
42+
{ index: 0, _id: ObjectId("627bf4f95e19ff3518448883") },
43+
{ index: 1, _id: ObjectId("627bf4f95e19ff3518448884") }
44+
],
45+
matchedCount: 0,
46+
modifiedCount: 0,
47+
deletedCount: 0,
48+
upsertedCount: 0,
49+
upsertedIds: []
50+
}
3851

3952
.. seealso::
4053

source/reference/method/Bulk.tojson.txt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
=============
2-
Bulk.tojson()
2+
Bulk.toJSON()
33
=============
44

55
.. default-domain:: mongodb
@@ -10,7 +10,7 @@ Bulk.tojson()
1010
:depth: 1
1111
:class: singlecol
1212

13-
.. method:: Bulk.tojson()
13+
.. method:: Bulk.toJSON()
1414

1515
Returns a JSON document that contains the number of operations and
1616
batches in the :method:`Bulk()` object.
@@ -20,21 +20,33 @@ Example
2020

2121
The following initializes a :method:`Bulk()` operations builder on the
2222
``items`` collection, adds a series of write operations, and calls
23-
:method:`Bulk.tojson()` on the ``bulk`` builder object.
23+
:method:`Bulk.toJSON()` on the ``bulk`` builder object.
2424

2525
.. code-block:: javascript
2626

2727
var bulk = db.items.initializeOrderedBulkOp();
2828
bulk.insert( { item: "abc123", status: "A", defaultQty: 500, points: 5 } );
2929
bulk.insert( { item: "ijk123", status: "A", defaultQty: 100, points: 10 } );
30-
bulk.find( { status: "D" } ).removeOne();
31-
bulk.tojson();
30+
bulk.find( { status: "D" } ).deleteOne();
31+
bulk.toJSON();
3232

33-
The :method:`Bulk.tojson()` returns the following JSON document
33+
The :method:`Bulk.toJSON()` returns the following JSON document
3434

3535
.. code-block:: javascript
3636

37-
{ "nInsertOps" : 2, "nUpdateOps" : 0, "nRemoveOps" : 1, "nBatches" : 2 }
37+
{
38+
acknowledged: true,
39+
insertedCount: 2,
40+
insertedIds: [
41+
{ index: 0, _id: ObjectId("627bf77e5e19ff3518448887") },
42+
{ index: 1, _id: ObjectId("627bf77e5e19ff3518448888") }
43+
],
44+
matchedCount: 0,
45+
modifiedCount: 0,
46+
deletedCount: 0,
47+
upsertedCount: 0,
48+
upsertedIds: []
49+
}
3850

3951
.. seealso::
4052

0 commit comments

Comments
 (0)