That is the continuation of Getting Began with MongoDB Atlas – Half 1. Our Dataset is prepared. Now let’s create a .Web Core Console App by which we are going to attempt to entry one of many collections within the MongoDB Atlas cluster.
Give a reputation to your .Web Core mission. Click on on the Create button.
As soon as the answer is prepared, right-click on the mission’s dependencies and choose Handle NuGet Packages.
Now set up MongoDB Driver from NuGet bundle supervisor as proven within the beneath picture. Click on on the Set up button, so as to set up the bundle.
With a purpose to join C# .Web Core Software with the MongoDB Atlas’s Cluster, we want a connection string. Click on on the join button of the Cluster created.
A popup will seem from the place we’ve got to decide on a connection technique. Click on on the Join your software hyperlink as proven within the beneath picture.
Choose Driver and the Model of the Driver (put in by NuGet bundle supervisor) which we’re utilizing to attach with MongoDB by the C# .Web Core console software. Click on on the copy button so as to copy the connection string. Change to the password added for the database consumer and to the database title with which you wish to join.
There are a number of databases within the Pattern Dataset loaded. We’ll use the sample_mflix database within the connection string.
Now add the beneath C# Code in the principle technique of the .Web Core Console Software.
//Passing the connection string in MongoClient var consumer = new MongoClient(“mongodb+srv://TestUser:PASSWORD@cluster0.maoqh.mongodb.web/pattern?retryWrites=true&w=majority”); //Get sample_mflix Database var db = consumer.GetDatabase(“sample_mflix”); //Get motion pictures assortment var assortment = //Discover doc with title Peter Pan var outcome=assortment.Discover(“{title:’Peter Pan’}”).FirstOrDefault(); Console.WriteLine(outcome); |