Skip to content

Instantly share code, notes, and snippets.

@erikbeebe
Created November 29, 2012 02:36
Show Gist options
  • Save erikbeebe/4166414 to your computer and use it in GitHub Desktop.
Save erikbeebe/4166414 to your computer and use it in GitHub Desktop.
Code for mongosv
var Server = require('mongodb').Server;
var Db = require('mongodb').Db;
new Db('users',
new Server("localhost", 27017, {auto_reconnect:true}), {safe:true}).open(function(err, db) {
if (err) throw err;
db.authenticate('rocketuser', 'rocketpass', function(autherr, result) {
if (autherr) throw autherr;
db.collection('accounts', function(colerr, collection) {
if (colerr) throw colerr;
// Define a simple JSON document
var doc = {'login': 'bob', 'password': 'secret'}
// Insert our document
collection.insert(doc, {}, function(){});
// Change our password
collection.update({'login': 'bob'},
{'$set': {'password': 'notsosecret'}},
function(){});
// Retrieve our document
collection.findOne({}, function(finderr, docs) {
if (finderr) {
console.log(finderr);
} else {
return console.log(docs);
};
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment