node. JS connection MONGO Replica set

Source: Internet
Author: User
Tags db connect mongoclient

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.