To find your MongoDB Atlas connection string, follow these steps:
Log in to MongoDB Atlas
Go to MongoDB Atlas.
Sign in with your credentials.Select Your Cluster
Click on the Clusters tab.
Select the cluster you want to connect to.Get the Connection String
Click on the "Connect" button.
Select "Drivers" or "Connect your application" (if using Node.js).
Choose Node.js as the driver and select the appropriate version.
Copy the provided connection string (it looks like this):
mongodb+srv://<username>:<password>@cluster0.xxxxx.mongodb.net/<database>?retryWrites=true&w=majority
Replace Placeholders
Replace with your database username.
Replace with your database password.
Replace with the database name you want to connect to.
Example for Node.js (Mongoose)
const mongoose = require('mongoose');
const uri = "mongodb+srv://yourUser:yourPassword@cluster0.xxxxx.mongodb.net/yourDB?retryWrites=true&w=majority";
mongoose.connect(uri, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => console.log("Connected to MongoDB Atlas"))
.catch(err => console.error("Error connecting to MongoDB Atlas:", err));
Top comments (0)