Find Multiple Documents
On this page
You can retrieve multiple documents from a collection by using the
Find()
method.
Examples
The examples on this page use the following Restaurant
, Address
, and GradeEntry
classes as models:
public class Restaurant { public ObjectId Id { get; set; } public string Name { get; set; } [ ] public string RestaurantId { get; set; } public string Cuisine { get; set; } public Address Address { get; set; } public string Borough { get; set; } public List<GradeEntry> Grades { get; set; } }
public class Address { public string Building { get; set; } [ ] public double[] Coordinates { get; set; } public string Street { get; set; } [ ] public string ZipCode { get; set; } }
public class GradeEntry { public DateTime Date { get; set; } public string Grade { get; set; } public float Score { get; set; } }
Note
The documents in the restaurants
collection use the camel-case naming
convention. The examples in this guide use a ConventionPack
to deserialize the fields in the collection into Pascal case and map them to
the properties in the Restaurant
class.
To learn more about custom serialization, see Custom Serialization.
Find Documents Using Builders
The following example uses Builders
to find documents in
the restaurants
collection with the cuisine
"Pizza".
Select the Asynchronous or Synchronous tab to see the corresponding code.
Find Documents Using LINQ
The following example uses LINQ to find documents in the
restaurants
collection with the cuisine
"Pizza".
Select the Asynchronous or Synchronous tab to see the corresponding code.
Find All Documents
The following example finds all documents in the restaurants
collection.
Select the Asynchronous or Synchronous tab to see the corresponding code.
Expected Result
Running the preceding full examples prints the following results:
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 sample datasets 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 Retrieve Data guide.
To learn more about using builders, see Operations with Builders.
To learn how to find documents using LINQ, see LINQ.