This repository contains a very basic example application built with the C# MongoDB Driver that connects to MongoDB Atlas. You can use this console application as a starting point and reference when building your C# applications.
To build and run this project, you will need Visual Studio 2019 Community Edition for MacOS or Windows, which you can download here: VS Community 2019 Downloads.
It is also helpful, but not necessary, to have a working installation of Git version control.
The following instructions explain how to get this project connected to your instance of MongoDB Atlas.
To get started with this sample project, download this repository to your programming environment. You can close this project using Git version control:
git clone [email protected]:mongodb-university/atlas_starter_dotnet.git
Or you can download the ZIP archive using your browser. If you download this project as a ZIP archive, unzip the archive before proceeding.
-
In Visual Studio, select
File > Open...
-
Navigate to the directory containing this project, and then the AtlasStarter folder.
-
Select the AtlasStarter.sln file, and then click
OK
.
-
Open the
Program.cs
file. -
On line 17, replace the placeholder text with the connection string to your Atlas cluster. For more information on finding the connection string, see Connect via Driver.
var mongoUri = "<Your Atlas Connection String>";
- Click the Run icon, or from the Run menu, choose Start Debugging.
Assuming you have the correct connection string, you have now connected the C# app to your MongoDB Atlas datastore. Have fun modifying the code to experiment with the C# driver and MongoDB.
Are you having trouble getting connected to your MongoDB Atlas instance? Double-check the following:
-
Have you replaced the
mongoUri
variable with a valid connection string provided by the Atlas UI? -
Have you whitelisted your current IP address in the Atlas UI?