如何在 Mongoose 中添加其他文档的同时读取文档?

How to read documents while adding other documents in Mongoose?

我的应用程序接收一个新文档并随时将其保存到数据库中。如何确保在保存新文档的同时阅读现有文档的最坏情况不会发生冲突?

我认为您应该没有问题,因为插入和更新操作在 mongoDB

中应该是原子的

来自文档:

In MongoDB, a write operation is atomic on the level of a single document, even if the operation modifies multiple embedded documents within a single document.