Created
November 29, 2012 02:36
-
-
Save erikbeebe/4166414 to your computer and use it in GitHub Desktop.
Code for mongosv
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 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