Preventing database-related race conditions in Node.js

前端 未结 1 1283
面向向阳花
面向向阳花 2021-02-05 04:12

Overview

I am attempting to understand how to ensure aynchronous safety when using an instance of a model when using Node.js. Here, I use the Mongoose ODM in code sam

相关标签:
1条回答
  • 2021-02-05 04:21

    No, there are no guarantees that this type of race condition won't occur in node.js/MongoDB. It doesn't have anything to do with node.js though, and this is possible with any database that supports concurrent access, not just MongoDB.

    The problem is, however, trickier to solve with MongoDB because it doesn't support transactions like your typical SQL database would. So you have to solve it in your application layer using a strategy like the one outlined in the MongoDB cookbook here.

    0 讨论(0)
提交回复
热议问题