var url, mongoose, options,dataSource;
mongoose = require('mongoose');
mongoose.Promise = global.Promise;
url = 'mongodb://127.0.0.1:27017/test' ;
options = {
db: {
native_parser: true
},
server: {
auto_reconnect: true,
poolSize: 5
}
};
mongoose.connect(url, options, function (err, res) {
if (err) {
console.log('[mongoose log] Error connecting to: ', +url + '. ' + err);
return process.exit(1);
} else {
return console.log('[mongoose log] Successfully connected to: ', +url);
}
});
dataSource = mongoose.connection;
dataSource.on('error', console.error.bind(console, 'mongoose connection error:'));
dataSource.once('open', function () {
return console.log('mongoose open success');
});
module.exports = dataSource;
nodejs 连接mongodb
最新推荐文章于 2024-02-27 11:51:30 发布