Getting Started Wth MongoDb Atlas


In this article, we will learn how to get started with MongoDB Atlas. MongoDB Atlas is the global cloud database service for the modern application. MongoDB Atlas is the best way to deploy, run, and scale MongoDB In the Cloud.
Let's begin...
First of all, visit URL in order to Signup for the MongoDB Atlas Account.
The next step is to add an organization. Within the organization, we can create projects, invite users, and can set up a billing account as well.
Give a name to your organization and select the MongoDB Atlas as a Cloud Service. Click on Next.
Click on the create organization button in order to create an organization.
Click on the New Project button in order to add the project to the Organization.
Provide a Name to your Project. The project name must be unique within an organization. Click on the Next button.
Click on Create Project in order to add the Project to the organization.
The next step is to Add a Cluster to the Project. Click on Build a Cluster in order to create a Cluster.
Select the Cluster as per your requirement. I am choosing a shared cluster as I am using it for demonstration purposes.
Shared Cluster is for Team learning MongoDB or developing small applications. Click on the Create a Cluster button, as shown in the below image.
Select a starter Cluster in Shared Cluster. Pick the Cloud Provider and Region where you want to create a Cluster. Click on the Create a Cluster button.
It will take around 3 minutes to set up a cluster in the cloud. You can also add another cluster by clicking on the Add a new Cluster button (if needed).
Once the cluster is ready, the Connect, Metrics, and Collections button will be enabled.
Click on the Network Access menu and then Add click on the IP Address button as Atlas only allows client connections to a cluster from entries in a Project’s IP Address list.
For Demonstration, I am allowing Access from Anywhere in the IP Address Access List (as we will access the same cluster through the .NET Core Application). Click on Confirm in order to proceed.
Once added, you can see the whitelist IP Address in the grid. You can edit or delete any allowed IP Address at any time.
Now click on the Database access menu in order to create a Database user, setup permission, and authentication credentials to connect with a cluster. Click on Add new database user.
Select the Password as the Authentication method, type or auto-generate secure password, give read and write to any database. Click on Add user.
All of the added users visible in the grid in the Database user tab.
Click on three dots (options) in Sandbox Cluster, Click on Load Sample Dataset. A sample dataset which is of around 350 MB in size will be loaded in the cluster.
The sample dataset will be loaded in a few minutes.
Our Dataset is ready. Now let’s create a .NET Core Console App through which we will try to access one of the collections in the MongoDB Atlas cluster.
Give a name to your .NET Core project. Click on the Create button.
Once the solution is ready, right-click on the project’s dependencies and select Manage NuGet Packages.
Now install MongoDB Driver from NuGet package manager as shown in the below image. Click on the Install button, in order to install the package.
In order to connect C# .Net Core Application with the MongoDB Atlas’s Cluster, we need a connection string. Click on the connect button of the Cluster created.
A popup will appear from where we have to choose a connection method. Click on the Connect your application link as shown in the below image.
Select the Driver and the Version of the Driver (installed through NuGet package manager) which we are using to connect with MongoDB through the C# .NET Core console application. Click on the copy button in order to copy the connection string. Change <password> to the password added for the database user and <dbname> to the database name with which you want to connect.
There are multiple databases in the Sample Dataset loaded. We will use the sample_mflix database in the connection string.
Now add the below C# Code in the main method of the .NET Core Console Application.
  1. //Passing the connection string in MongoClient  
  2. var client = new MongoClient("mongodb+srv://");  
  3. //Get sample_mflix Database  
  4. var db = client.GetDatabase("sample_mflix");  
  5. //Get movies collection  
  6. var collection = db.GetCollection<BsonDocument>("movies");  
  7. //Find document with title Peter Pan  
  8. var result=collection.Find("{title:'Peter Pan'}").FirstOrDefault();  
  9. Console.WriteLine(result);  
On running the application, a document with Title “Peter Pan” will be printed on the console.
I hope this will help you get started with MongoDB Atlas.