O
O
olegan_092020-01-29 10:25:39
MongoDB
olegan_09, 2020-01-29 10:25:39

How to properly connect MongoDB Atlas on hosting?

I can't connect to MongoDB Atlas specifically on the hosting, everything works fine on the local one. Already tried everything I could find on the Internet.
I connect like this:

mongoose
  .connect(
    'mongodb://<username>:<password>@cluster0-shard-00-00-eveil.mongodb.net:27017,cluster0-shard-00-01-eveil.mongodb.net:27017,cluster0-shard-00-02-eveil.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true&w=majority',
    { useNewUrlParser: true }
  )
  .then(() => console.log('MongoDB Connected...'))
  .catch(err => console.log(err));


Initially I tried with the following connection string:
mongodb+srv://<username>:<password>@cluster0-eveil.mongodb.net/test?retryWrites=true&w=majority


The white sheet contains all the necessary IPs, as well as 0.0.0.0/0 for the duration of the test (to connect from any ip). I tried to add a new database admin, which I did not use on the local machine.

When launched on hosting, beget does not register errors for me, but the react application starts up completely and works, only in requests where a connection to the database is required, it gives an error 500 (Internal Server Error)

I tried to connect to firebase, it also works there, only registered some errors depending on my code changes:
Error: querySrv EREFUSED _mongodb._tcp.cluster0-eveil.mongodb.net
    at QueryReqWrap.onresolve [as oncomplete] (dns.js:196:19)

MongoNetworkError: failed to connect to server [cluster0-shard-00-02-eveil.mongodb.net:27017] on first connect [MongoNetworkError: getaddrinfo EAI_AGAIN cluster0-shard-00-02-eveil.mongodb.net:27017]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
olegan_09, 2020-01-29
@olegan_09

Understood with firebase. In the free plan, it does not support such connections. Everything worked on the paid plan.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question