I am using the mongodb driver and monk on nodejs. Examples such as this that I see on the Web have the following pattern:
var mongo = require('mongodb');
var monk = require('monk');
var db = monk('localhost:27017/userdb');
var collection = db.get('users');
collection.find({}, function(err, docs) {
});
Two questions:
- Why is the first line needed: var mongo = require('mongodb')? The variable mongo is never used. Wouldn't monk automatically require mongodb?
- I see at the driver level, the db has to be opened and closed. These methods don't seem to exist at the monk level. Does monk automatically open and close connections? How does this work?
As a matter of fact, I am wondering what advantage does monk provide over using the driver directly. I read the list of features in the monk docs, but don't really understand the benefits.
Thanks in advance for your help.