连接选项和回调

Mongoose connect 有 3 个参数,uri,options 和回调函数。要使用它们,请参阅下面的示例

var mongoose = require('mongoose');

var uri = 'mongodb://localhost:27017/DBNAME';

var options = {
    user: 'user1',
    pass: 'pass'
}

mongoose.connect(uri, options, function(err){
    if (err) throw err;
    // if no error == connected
});