-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathfindMany.txt
179 lines (128 loc) · 5.15 KB
/
findMany.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
.. _csharp-find-multiple:
=======================
Find Multiple Documents
=======================
.. facet::
:name: genre
:values: reference
.. meta::
:keywords: code example, .NET, operation
:description: Retrieve multiple documents from a collection using the `Find()` method in C# with examples for both asynchronous and synchronous operations.
.. contents:: On this page
:local:
:backlinks: none
:depth: 2
:class: singlecol
You can retrieve multiple documents from a collection by using the
``Find()`` method.
Example
-------
Find Documents by Using Builders
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following example uses ``Builders`` to find documents in
the ``restaurants`` collection with the ``cuisine`` "Pizza".
Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the
corresponding code.
.. tabs::
.. tab:: Synchronous
:tabid: builders-sync
.. literalinclude:: ../includes/code-examples/find-many/FindMany.cs
:start-after: start-find-builders-sync
:end-before: end-find-builders-sync
:language: csharp
:copyable:
:dedent:
For a fully runnable example of using the ``Find()`` method to synchronously
find multiple documents, see
`Synchronous Find Multiple Example <{+example+}/find-many/FindMany.cs>`__.
.. tab:: Asynchronous
:tabid: builders-async
.. literalinclude:: ../includes/code-examples/find-many/FindManyAsync.cs
:start-after: start-find-builders-async
:end-before: end-find-builders-async
:language: csharp
:copyable:
:dedent:
For a fully runnable example of using the ``Find()`` method to asynchronously
find multiple documents, see
`Asynchronous Find Multiple Example <{+example+}/find-many/FindManyAsync.cs>`__.
Find Documents by Using LINQ
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following example uses LINQ to find documents in the
``restaurants`` collection with the ``cuisine`` "Pizza".
Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the
corresponding code.
.. tabs::
.. tab:: Synchronous
:tabid: linq-sync
.. literalinclude:: ../includes/code-examples/find-many/FindMany.cs
:start-after: start-find-linq-sync
:end-before: end-find-linq-sync
:language: csharp
:copyable:
:dedent:
For a fully runnable example of using the ``Find()`` method to synchronously
find multiple documents, see
`Synchronous Find Multiple Example <{+example+}/find-many/FindMany.cs>`__.
.. tab:: Asynchronous
:tabid: linq-async
.. literalinclude:: ../includes/code-examples/find-many/FindManyAsync.cs
:start-after: start-find-linq-async
:end-before: end-find-linq-async
:language: csharp
:copyable:
:dedent:
For a fully runnable example of using the ``Find()`` method to asynchronously
find multiple documents, see
`Asynchronous Find Multiple Example <{+example+}/find-many/FindManyAsync.cs>`__.
.. _csharp_find_all:
Find All Documents
~~~~~~~~~~~~~~~~~~
The following example finds all documents in the ``restaurants`` collection.
Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the
corresponding code.
.. tabs::
.. tab:: Synchronous
:tabid: find-all-sync
.. literalinclude:: ../includes/code-examples/find-many/FindMany.cs
:start-after: start-find-all-sync
:end-before: end-find-all-sync
:language: csharp
:copyable:
:dedent:
For a fully runnable example of using the ``Find()`` method to synchronously
find multiple documents, see
`Synchronous Find Multiple Example <{+example+}/find-many/FindMany.cs>`__.
.. tab:: Asynchronous
:tabid: find-all-async
.. literalinclude:: ../includes/code-examples/find-many/FindManyAsync.cs
:start-after: start-find-all-async
:end-before: end-find-all-async
:language: csharp
:copyable:
:dedent:
For a fully runnable example of using the ``Find()`` method to asynchronously
find multiple documents, see
`Asynchronous Find Multiple Example <{+example+}/find-many/FindManyAsync.cs>`__.
Expected Result
~~~~~~~~~~~~~~~
Running the preceding full examples prints the following results:
.. code-block:: none
Finding documents with builders...:
Number of documents found: 1163
Finding documents with LINQ...:
Number of documents found: 1163
Finding all documents...:
Number of documents found: 25359
.. tip:: Sample Datasets
These examples use the :atlas:`sample datasets </sample-data>` provided by Atlas.
The number of documents returned may differ depending on the data in your
collection.
Additional Information
----------------------
To learn more about retrieving documents, see the :ref:`csharp-retrieve` guide.
To learn more about using builders, see :ref:`csharp-builders`.
To learn how to find documents using LINQ, see :ref:`csharp-linq`.
API Documentation
-----------------
- `Find() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoCollectionExtensions.Find.html>`__