TodMongoDB Atlas is a fully-managed cloud database developed by the same people that build MongoDB. Atlas handles all the complexity of deploying, managing, and healing your deployments on the cloud service provider of your choice (AWS, Azure, and GCP).

Click on this link and create a account https://www.mongodb.com/cloud/atlas/register
Then we have to create a Cluster

I am selecting AWS since i prefer it but you can chosoe whatever you want then I am selecting ASIA – Mumbai as the sever choose whatever closest to you

It will take some time to build your cluster then Click connect.Then create an account to access database

go back to your cluster and click connect

Then select “Connect your Application” and select the Driver and version as Follows, after that copy the code

Okay now you are done with getting necessary details make a connection.Now open your express app and type following commands
NPM i mongodb –save
NPM i mongoose –save
In the application include this code
const mongoose = require('mongoose');
const MongoClient = require('mongodb').MongoClient;
const uri = "mongodb+srv://rashmika:1234@fashionstore-k14re.mongodb.net/test?retryWrites=true&w=majority"
MongoClient.connect(uri, function (err, client) {
if (err) {
console.log('Error occurred while connecting to MongoDB Atlas...\n', err);
}
console.log('Connected...');
const collection = client.db("test").collection("devices");
// perform actions on the collection object
client.close() ;
});
Cool Now you save data in the atlas cluser!!!!!
Leave a comment