使用Mongoose时的MongoDB弃用警告 [英] MongoDB deprecation warnings when using Mongoose
问题描述
我正在使用猫鼬版本 5.2.13 ,我认为是最新版本.但是,当我尝试执行 .findOneAndUpdate()查询时,Mongo会引发弃用警告:
I'm using mongoose version 5.2.13, the latest I suppose. But when I try executing the .findOneAndUpdate() query, Mongo throws a deprecation warning:
DeprecationWarning:不建议使用collection.findAndModify.使用 而不是findOneAndUpdate,findOneAndReplace或findOneAndDelete.
DeprecationWarning: collection.findAndModify is deprecated. Use findOneAndUpdate, findOneAndReplace or findOneAndDelete instead.
在猫鼬的未来版本中应该解决此已知行为吗?还是我应该对此做些什么?我正在运行的查询是:
Is this known behavior that should be fixed in future versions of mongoose? Or should I do something about it? The query I'm running is:
output2 = await dbUser.findOneAndUpdate(
{ _id: args.authorid },
{ $push: { posts: newpost2 } },
);
如果这是推荐答案
参考: https://mongoosejs .com/docs/deprecations.html 添加参数: useFindAndModify:false 例如代码: 这篇关于使用Mongoose时的MongoDB弃用警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! mongoose.connect(
MONGODB_URL, {
useFindAndModify: false
},
(err, db) => {
if (err) throw err;
console.log(`MongoDB connected on port ${MONGODB_PORT}`);
}
);