Usage Examples
On this page
Overview
Usage examples provide convenient starting points for popular MongoDB operations. Each example provides the following information:
A code snippet that shows how to perform the operation in synchronous and asynchronous frameworks
A link to a fully runnable console application using the operation
The expected result after running the example
How to Use the Usage Examples
These examples use the sample datasets provided by Atlas. You can load them into your database on the free tier of MongoDB Atlas by following the Get Started with Atlas Guide or you can import the sample dataset into a local MongoDB instance.
Once you have imported the dataset, you can copy and paste a usage example into your development environment of choice. You can follow the Quick Start to learn more about getting started with the MongoDB .NET/C# Driver. Once you've copied a usage example, you'll need to edit the connection URI to get the example connected to your MongoDB instance:
// Replace the following with your MongoDB deployment's connection string. private static string _mongoConnectionString = "<connection string>";
For more information about connecting to your MongoDB instance, see the Connection Guide.