Recently got a copy set of MongoDB, tested today under node. JS Call replica set script, test pass. Record them.
varMongoclient = require (' MongoDB '). mongoclient;//Mongodb://user:[email protected]:p the full format of the Ort/dbname?replicaset=replicasetname connection, the replica set does not need to write out a list of all the servers, Only part of the write is also available, but if there is a problem with the part of the server, whether it will fail and be confirmed latervarurl = ' Mongodb://wayne:[email protected]:27018,192.168.75.132:27019/wayne_com?replicaset=rs '; Mongoclient.connect (URL,function(err, db) {Console.log (' Error ', ' DB Connect is OK '); varCollection = Db.collection (' test_list ')); Console.log (' Error ', ' collection is OK '); Collection.find ({}). ToArray (function(err, result) {Console.log (err, result); });});
node. JS connection MONGO Replica set