您几乎可以忽略该问题并使用Mongoose.connect(databaseUri, { useMongoClient: true })
。
如果您确实想避免出现警告,请避免使用4.11.0版本。
我更新到4.11.1版本,因为@类型/猫鼬@尚未进行更新4.7.18和他们不提现场useMongoClient
的ConnectionOptions
,我这是怎么导入模块:
const Mongoose = require('mongoose');
然后用了这个功能:
private connectDatabase(databaseUri: string): Promise<any> {
return Mongoose.connect(databaseUri, { useMongoClient: true })
.then(() => {
console.log('Connected to MongoDB at ', databaseUri);
return Mongoose.connection;
})
.catch(err => debug(`Database connection error: ${err.message}`));
}