What is the difference between connecting mongodb.connect vs MongoClient.connect?
Sometimes I see this:
var mongodb = require( 'mongodb' ),
express = require( 'express' ),
node_acl = require( 'acl' ),
port = 3500,
app = express(),
// The actual acl will reside here
acl;
mongodb.connect( 'mongodb://127.0.0.1:27017/acl_example', _mongo_connected );
function _mongo_connected( error, db ) {
if (error) throw error;
var mongoBackend = new node_acl.mongodbBackend( db /*, {String} prefix */ );
// Create a new access control list by providing the mongo backend
// Also inject a simple logger to provide meaningful output
acl = new node_acl( mongoBackend, logger() );
// Defining roles and routes
set_roles();
set_routes();
}
and then
http://blog.modulus.io/mongodb-tutorial
//lets require/import the mongodb native drivers.
var mongodb = require('mongodb');
//We need to work with "MongoClient" interface in order to connect to a mongodb server.
var MongoClient = mongodb.MongoClient;
// Connection URL. This is where your mongodb server is running.
var url = 'mongodb://localhost:27017/my_database_name';
// Use connect method to connect to the Server
MongoClient.connect(url, function (err, db) {
if (err) {
console.log('Unable to connect to the mongoDB server. Error:', err);
} else {
//HURRAY!! We are connected. :)
console.log('Connection established to', url);
// do some work here with the database.
//Close connection
db.close();
}
});
Essentially correct connection is the same either way. So what is the difference?