const mongoose = require(‘mongoose‘)
// 如果数据库(database)不存在就会创建
mongoose.connect(‘mongodb://localhost/eg‘,
{ useNewUrlParser: true, useUnifiedTopology: true },
function (err) {
if (err)
console.log(‘连接数据库失败‘);
else {
console.log(‘连接数据库成功‘);
}
})
function connect(
uris: string,
options: mongoose.ConnectOptions,
callback: (err: MongoError) => void
)
//Opens the default mongoose connection.
原文:https://www.cnblogs.com/dingtongya/p/14782717.html