Created
January 29, 2013 03:22
-
-
Save ivanstoyanov/4661530 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var connectString = "mongodb://user:password@hostname_1:30000,hostname_2:30001,hostname_3:30002/admin?replicaSet=myset&autoReconnect=true"; | |
| var mongo = require('mongodb'); | |
| var async = require('async'); | |
| var admin_db; | |
| var db1; | |
| var db2; | |
| var simpleQuery = function(callback) { | |
| if (db1==null) { | |
| db1 = admin_db.db('db1'); | |
| } | |
| db1.collection('foo').findOne({}, function (err, results) { | |
| console.log(results); | |
| if (db2==null) { | |
| db2 = admin_db.db('db2'); | |
| } | |
| db2.collection('bar').findOne({}, function (err, results) { | |
| console.log(results); | |
| setTimeout(callback, 2000); | |
| }); | |
| }); | |
| } | |
| mongo.connect(connectString, {db: {safe: true}}, function (err, db) { | |
| if (typeof err !== "undefined" && err !== null) { | |
| console.log (err); | |
| } else { | |
| admin_db = db; | |
| console.log('connected'); | |
| async.whilst( | |
| function() { | |
| return true; | |
| }, | |
| function(callback) { | |
| simpleQuery(callback); | |
| }, | |
| function() { | |
| console.log("done"); | |
| } | |
| ); | |
| } | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment