Mongoose.js transactions

前端 未结 6 1026
栀梦
栀梦 2021-01-30 18:14

I know MongoDB doesn\'t support transactions as relational databases do, but I still wonder how to achieve atomicity for several operations. Hunting around the web, I see people

6条回答
  •  旧巷少年郎
    2021-01-30 18:19

    Transactions are not supported in MongoDB out of the box. However they are implementable with Two-phase commit protocol. Here you can see official recommendation on how to do 2PCs in MongoDB. This approach is quite universal and can be applied to different scenarios such as

    • documents from different collections (your case)
    • more than 2 documents
    • custom actions on documents

提交回复
热议问题