使用nodejs mongodb串連mongodb的shard分布服務,nodejsmongodb

來源:互聯網
上載者:User

使用nodejs mongodb串連mongodb的shard分布服務,nodejsmongodb

1,串連單個mongodb的執行個體,可以參看node mongodb的文檔


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


2, 串連mongodb 的mongos服務,只需要修改一下串連配置即可,如下

var MongoClient = require('mongodb').MongoClient  , format = require('util').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);MongoClient.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();});


相關文章

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.