Mark Mark - 1 month ago 10
Node.js Question

How do I connect to mongodb with node.js (and authenticate)?

How do I connect to mongodb with node.js?

I have the node-mongodb-native driver.

There's apparently 0 documentation.

Is it something like this?

var mongo = require('mongodb/lib/mongodb');
var Db= new mongo.Db( dbname, new mongo.Server( 'mongolab.com', 27017, {}), {});


Where do I put the username and the password?

Also how do I insert something?

Thanks.

Answer

Per the source:

After connecting:

Db.authenticate(user, password, function(err, res) {
  // callback
});
Comments