mongoose 连接成功,但是发出警告,好像是新版本要修改哪?错误信息如下
DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0,use `openUri()` instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`
网上找了半天没有结果,求答案,附上连接代码
var mongoose = require('mongoose')
mongoose.connect('mongodb://localhost/test');
var db = mongoose.connection
db.on('error', console.error.bind(console, '连接错误:'));
db.once('open', function() {
console.log('连接成功');
})
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
最新版mongoose的已知问题,你可以先降级至4.10.8版,或者试试下面的方法不知道有没有用: