Use nodejs mongodb to connect to mongodb's shard distribution service, nodejsmongodb

Source: Internet
Author: User
Tags mongodb documentation

Use nodejs mongodb to connect to mongodb's shard distribution service, nodejsmongodb

1. For more information about connecting to a single mongodb instance, see the node mongodb documentation.


Https://github.com/mongodb/node-mongodb-native


2. To connect to mongodb's mongos service, you only need to modify the connection configuration as follows:

Var login client = require ('mongodb '). using client, format = require ('til '). format; var url = format ("mongodb: // % s, % s/% s", "192.168.0.60: 27017", "192.168.0.64: 27017", "test "); // var url = "mongodb: // 192.168.0.60/test"; console. log (url); login client. connect (url, function (err, db) {if (! Err) {var collection = db. collection ('test'); console. log (collection); collection. find ({}). toArray (function (errfind, items) {if (! Errfind) {console. log (items);} else {console. log (errfind);} db. close () ;}); console. log ("We are connected");} // db. close ();});


Related Article

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.