弃用警告:collection.insert 已弃用。改为使用 insertOne、insertMany 或 bulkWrite

DeprecationWarning: collection.insert is deprecated. Use insertOne, insertMany or bulkWrite instead

我正在为 Ionic 前端开发 LoopBack 后端。它使用 MongoDB 作为数据库。

package.json 中,我尝试将依赖项 loopback-connector-mongodb^3.4.1 升级到 ^3.6.0,但是我面临这种警告。

DeprecationWarning: collection.insert is deprecated. Use insertOne, insertMany or bulkWrite instead.

但是,我仍然没有找到解决方案,所以我想我必须再次降级。 (如果是这样,就没有这样的警告¯_(ツ)_/¯ )

有更好的解决办法吗?谢谢。

我在下面发现了一些 github 个问题,确信这个问题现在已经得到解决。

现在我升级了^4.2.0版本,一切似乎都还好。

谢谢

而不是 db.insert 写入 db.insertMany 用于插入多个数据 对于单个数据 db.insert一个