To find your MongoDB Atlas connection string, follow these steps:

  1. Log in to MongoDB Atlas
    Go to MongoDB Atlas.
    Sign in with your credentials.

  2. Select Your Cluster
    Click on the Clusters tab.
    Select the cluster you want to connect to.

  3. Get the Connection String

  4. Click on the "Connect" button.

  5. Select "Drivers" or "Connect your application" (if using Node.js).

  6. Choose Node.js as the driver and select the appropriate version.
    Copy the provided connection string (it looks like this):

mongodb+srv://:@cluster0.xxxxx.mongodb.net/?retryWrites=true&w=majority
  1. Replace Placeholders

  2. Replace with your database username.

  3. Replace with your database password.

  4. Replace with the database name you want to connect to.
    Example for Node.js (Mongoose)

const mongoose = require('mongoose');

const uri = "mongodb+srv://yourUser:[email protected]/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));