使用 mongoose 4.11 后 Mongoose model.find({}) 不起作用;
我注意到 Mongoose 在更新到 mongoose 4.11 后行为不正常,更新后屏幕上显示警告
DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead
所以我尝试了
let mongoConnectionLocal = {
'url': 'mongodb://username:password@localhost:27017/image-upload-gcs'
};
mongoose.connect(mongoConnectionLocal.url, { auth:{authdb:"admin"}, useMongoClient: true}, err => { if(err) { console.log(err.stack); }});
然后出现另一个警告
the options [auth] is not supported
所以我尝试了,
mongoose.connect('mongodb://username:password@localhost:27017/image-upload-gcs?authSource=admin', { useMongoClient: true}, err => { if(err) { console.log(err.stack); }});
现在 mongoose 不再工作,甚至无法使用 model.find({}) 或创建文档
我尝试恢复到 mongoose 4.10,一切正常。那么这是 mongoose 4.11 及以上版本中的一个错误吗???
最佳答案
您可以尝试下面的代码片段
mongoose.connect(mongoConnectionLocal.url);
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error'));
db.once('open', function callback(){
console.log("Connection with database succeeded.");
});
关于node.js - Mongoose model.find({}) 使用 mongoose 4.11 后不起作用; [漏洞??],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44838705/