連線選項和回撥

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
});