1

i need set remote connection to MongoDB, but i need make it via mongojs.

var docdbconn = mongojs('mongodb+srv://mylogin:mypassword@cluster0-m1s1a.mongodb.net/nameofdatabase?retryWrites=true');

and usually i get next error:

MongoError: failed to connect to server [cluster0-m1s1a.mongodb.net:27017] on first connect [MongoError: getaddrinfo ENOTFOUND cluster0-m1s1a.mongodb.net cluster0-m1s1a.mongodb.net:27017]
Max
  • 781
  • 7
  • 19

2 Answers2

0

are you sure the port provided is the right one, if there is no port specified related to the doc it seems like the port 27017 is setted by default. Maybe you're remote database isn't on this port and you need in your connection string to manually specify it.

Guillaume D
  • 181
  • 11
  • i took connection string from documentation of MongoDB Atlas – Max Feb 26 '19 at 17:24
  • In your connection string did you replace nameofdatabase by the current name of your database? if you did it, it seems like you're using connection via ssl, did you verify the DNS configuration of the server on /etc/resolv.conf (supposing you host your database on linux), if you don't need to secure your exchanges did you try to add '&ssl=false' at the end of your connection string to override your connection protocol and disable ssl connection? – Guillaume D Feb 26 '19 at 17:36
  • i set current database name, but ssl [impossible](https://docs.atlas.mongodb.com/faq/#can-i-disable-ssl-tls-on-my-deployment) turn off – Max Feb 26 '19 at 18:20
0

I found a solution, so i used another string connection for MongoDB 3.4+ and it helped me.

var docdbconn = mongojs("mongodb://nickname:password@cluster0-shard-00-00-m1s1a.mongodb.net:27017,cluster0-shard-00-01-m1s1a.mongodb.net:27017,cluster0-shard-00-02-m1s1a.mongodb.net:27017/databasename?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true");
Max
  • 781
  • 7
  • 19
  • [Here's a good example of managing such connections](https://github.com/vitaly-t/connection-string-demo). – vitaly-t Jul 08 '19 at 18:10