Använd bara Mongos anslutnings-URL, som beskrivs i mogos docs:
mongodb://[username:[email protected]]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
Så din kod skulle se ut så här (enligt mongodbs npm-modulhandbok ):
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();
});
Lycka till!