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 ();});