mongojs icon indicating copy to clipboard operation
mongojs copied to clipboard

How to connect to mongo atlas?

Open Taxi4you opened this issue 3 years ago • 0 comments

I am trying to connect to mongo atlas cluster but I got the following error:

Error [MongoError]: failed to connect to server [<cluster-url>:27017] on first connect [Error: getaddrinfo ENOTFOUND <cluster-url>
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26) {
  name: 'MongoError'
}]

This is how I am trying to connect:

const dbuser = <user>;
const dbpass = <pass>;
const dbClusterUrl = <cluster-uri>;
const dbName = 'test';
const dbOptions = `retryWrites=true&w=majority`
const dbUri = `mongodb+srv://${dbuser}:${dbpass}@${dbClusterUrl}/${dbName}?${dbOptions}`;

const db = require('mongojs')(dbUri, []);

How can it be achieved?

Taxi4you avatar Jan 10 '22 14:01 Taxi4you