mongojs
mongojs copied to clipboard
How to connect to mongo atlas?
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?