在node.js中连接mongodb时,
mongoose.connect('mongodb://localhost:27018', function(error){
// 连接数据库之后的回调
if(error){
console.log('连接数据库失败');
console.log(error);
}
else{
console.log('连接数据库成功');
// 如果连接成功,就可以通过mongoose模块操作数据库
//连接成功,再启动服务
app.listen(8080);
}
});
报错 :
(node:12596) DeprecationWarning:
open()
is deprecated in mongoose >= 4.11.0, useopenUri()
instead, or set theuseMongoClient
option if usingconnect()
orcreateConnection()
. See http://mongoosejs.com/docs/co...
连接数据库成功
(node:12596) DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/pr...
报错都给出答案了。
你使用的open()方法已经不再支持了,使用openUri()来替代它。或者设置一下useMongoClient 的选项如果你使用connect()或createConnection()方法的话。
错误信息很关键,基本都告诉你怎么解决这个错误了。