Shuvo 93
Shuvo 93

Reputation: 1

mongodb remote connection developed with node.js hosting provier doesn't have build in?

I deployed my little website projected built node,js, and customised, with js, in local development I used database mongodb, in the hosting provider doesn't have the mongodb. They said to connect remotely.

How to connect remotely? I have already a cluster in mongodb atlast web, like connection string:

mongoose
    .connect('mongodb+srv://washimulislamData:<password>@mydata.d0jjezh.mongodb.net/signup?retryWrites=true&w=majority')
    .then(() => {
        console.log(`Connected to MongoDB`);
        app.listen(3000, () => {
            console.log(`Node API app is running on port 3000`);
        });
    })
    .catch((error) => {
        console.log(error);
    });

Upvotes: 0

Views: 30

Answers (1)

Longinus
Longinus

Reputation: 1

  • Make sure you replace with your actual database password. i suggest passing it through the .env file.
  • In the MongoDB Atlas dashboard, go to the "Network Access" section. Add an IP address to allow your hosting provider to access the MongoDB cluster.
  • Go to the "Database Access" section in MongoDB Atlas. Make sure your MongoDB user has the necessary permissions for the database you are connecting to.

Upvotes: 0

Related Questions