Skip to content

Instantly share code, notes, and snippets.

@dominiek
Created March 11, 2010 13:03
Show Gist options
  • Save dominiek/329106 to your computer and use it in GitHub Desktop.
Save dominiek/329106 to your computer and use it in GitHub Desktop.
db().open(function (db) {
db.collection('users', function(err, collection) {
collection.findOne({'username': self.params.get.username}, function (err, result) {
if(!result) {
var newUser = new User(self.params.get.username)
collection.insert([newUser.toJSON()], function(docs) {
db.close();
puts("Created new user: "+newUser.username)
self.halt(200, JSON.encode(newUser))
})
} else {
db.close();
puts("Fetched existing user: "+result.username)
self.halt(200, JSON.encode(result))
}
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment