Created
April 10, 2014 17:28
-
-
Save SauloSilva/10404476 to your computer and use it in GitHub Desktop.
Connect node with mongo
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 Db = require('mongodb').Db, | |
MongoClient = require('mongodb').MongoClient, | |
Server = require('mongodb').Server, | |
ReplSetServers = require('mongodb').ReplSetServers, | |
ObjectID = require('mongodb').ObjectID, | |
Binary = require('mongodb').Binary, | |
GridStore = require('mongodb').GridStore, | |
Code = require('mongodb').Code, | |
BSON = require('mongodb').pure().BSON, | |
assert = require('assert'); | |
var db = new Db('integration_tests', new Server("127.0.0.1", 27017, { | |
auto_reconnect: false, | |
poolSize: 4 | |
}), { | |
w: 0, | |
native_parser: false | |
}); | |
// Establish connection to db | |
db.open(function(err, db) { | |
assert.equal(null, err); | |
// Add a user to the database | |
db.addUser('user', 'name', function(err, result) { | |
assert.equal(null, err); | |
// Authenticate | |
db.authenticate('user', 'name', function(err, result) { | |
assert.equal(true, result); | |
db.close(); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment