Skip to content

Instantly share code, notes, and snippets.

@aheckmann
Created July 23, 2013 19:00
Show Gist options
  • Save aheckmann/6065153 to your computer and use it in GitHub Desktop.
Save aheckmann/6065153 to your computer and use it in GitHub Desktop.
node reconnect.js YOUR_CONNECTION_STRING
var mongo = require('mongodb');
console.log(mongo.version);
var uri = process.argv[1];
mongo.MongoClient.connect(uri, function (err, db) {
if (err) throw err;
var c = db.collection('test');
c.insert({ testing: true }, function (err) {
if (err) return done(err);
test()
})
function test () {
console.log('querying');
c.findOne(console.log);
}
setInterval(test, 1000)
function done (err) {
if (err) console.error(err);
db.close();
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment