更新:
Mongoose 5.2.10 版本已发布并可在此处下载。
有关文档的更多信息,您可以查看https://mongoosejs.com/docs/deprecations页面。
有关问题及其修复的更多信息,请参见https://github.com/Automattic/mongoose/issues/6880。
原始回答:
Mongoose 5.2.9 版本将本地 mongodb 驱动程序升级到 3.1.3 版本,其中添加了警告消息以在调用已弃用的本地驱动程序方法时抛出。
fields
选项已过时,并已替换为projection
选项。
您需要等待mongoose进行更改以将fields
选项替换为projection
。该修复计划在5.2.10版本中发布。
暂时您可以回退到5.2.8版本来禁止所有已弃用的警告。
npm install mongoose@5.2.8
对于所有其他的弃用警告,您必须逐个案例进行处理。
当您使用其他集合方法时,您会看到其他弃用警告。
DeprecationWarning: collection.findAndModify is deprecated. Use findOneAndUpdate, findOneAndReplace or findOneAndDelete instead.
DeprecationWarning: collection.remove is deprecated. Use deleteOne, deleteMany, or bulkWrite instead.
DeprecationWarning: collection.update is deprecated. Use updateOne, updateMany, or bulkWrite instead.
DeprecationWarning: collection.save is deprecated. Use insertOne, insertMany, updateOne, or updateMany instead.
DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.
所有的默认findOne*
mongoose 写法在底层都使用了已被mongodb原生驱动废弃的 findAndModify
方法。
为了让mongoose在mongodb原生驱动上调用合适的findOne*
方法,使用 mongoose.set('useFindAndModify', false);
。
remove
和 update
建议分别使用 delete*
和 update*
方法。
save
建议分别使用 insert*
/ update*
方法。
使用 mongoose.set('useCreateIndex', true);
来让mongoose在mongodb原生驱动上调用createIndex
方法。
npm install mongoose@5.2.8
应该可以解决问题。修复已经合并到主分支中了,详情请见 fix。因此,当5.2.10版本发布时,应该已经包含了这个修复。 - s7vr