-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathdeleteMany.txt
83 lines (59 loc) · 2.37 KB
/
deleteMany.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
74
75
76
77
78
79
80
81
82
83
.. _csharp-delete-many:
=====================
Delete Many Documents
=====================
.. facet::
:name: genre
:values: reference
.. meta::
:keywords: code example, .NET, operation
:description: Delete multiple documents in a collection using the `DeleteMany()` or `DeleteManyAsync()` methods in C#.
.. contents:: On this page
:local:
:backlinks: none
:depth: 2
:class: singlecol
You can delete more than one document using the ``DeleteMany()`` synchronous
method or the ``DeleteManyAsync()`` asynchronous method on a collection object.
Example
-------
The following code deletes all documents in the ``restaurants`` collection whose
``borough`` field value equals the word "Brooklyn".
Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding
code.
.. tabs::
.. tab:: Synchronous
:tabid: delete-many-sync
.. literalinclude:: ../includes/code-examples/delete-many/DeleteMany.cs
:start-after: start-delete-many-builders
:end-before: end-delete-many-builders
:language: csharp
:copyable:
:dedent:
For a fully runnable example of the ``DeleteMany()`` operation, see the
`DeleteMany code sample <{+example+}/delete-many/DeleteMany.cs>`__.
.. tab:: Asynchronous
:tabid: delete-many-async
.. literalinclude:: ../includes/code-examples/delete-many/DeleteManyAsync.cs
:start-after: start-delete-many-async
:end-before: end-delete-many-async
:language: csharp
:copyable:
:dedent:
For a fully runnable example of the ``DeleteManyAsync()`` operation, see the
`DeleteManyAsync code sample <{+example+}/delete-many/DeleteManyAsync.cs>`__.
Expected Result
~~~~~~~~~~~~~~~
Running either of the preceding full examples prints the following results:
.. code-block:: none
Deleting documents...
Deleted documents: 6086
Resetting sample data...done.
Additional Information
----------------------
To learn more about deleting documents, see the :ref:`csharp-delete-guide` guide.
To learn more about using builders, see :ref:`csharp-builders`.
API Documentation
-----------------
* `DeleteMany() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoCollection-1.DeleteMany.html>`__
* `DeleteManyAsync() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoCollection-1.DeleteManyAsync.html>`__