Mark Mark - 1 year ago 114
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( '', 27017, {}), {});

Where do I put the username and the password?

Also how do I insert something?


Answer Source

Per the source:

After connecting:

Db.authenticate(user, password, function(err, res) {
  // callback
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download