Gebruik gewoon de verbindings-URL van Mongo, zoals beschreven in mogo's documenten:
mongodb://[username:[email protected]]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
Dus je code zou er als volgt uitzien (volgens de mongodb's npm-modulehandleiding ):
const MongoClient = require('mongodb');
// Connection URL
const url = 'mongodb://[username:[email protected]]host1[:port1][,host2[:port2],...[,hostN[:portN]]]';
// Database Name
const dbName = '[dbName]';
// Use connect method to connect to the server
MongoClient.connect(url, function(err, client) {
assert.equal(null, err);
console.log("Connected successfully to server");
const db = client.db(dbName);
client.close();
});
Veel succes!