Mongoose model.find({})在使用mongoose4.11后无法工作;

Mongoose model.find({})在使用mongoose4.11后无法工作;

我注意到,更新到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({})或创build一个文档

我试着恢复到mongoose4.10,一切正常。 那么这是一个虫蛀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."); });