MongoDB is not suitable for strong transaction scenarios, but many scenarios often do not require strong transactions, and can be replaced by eventual consistency. Many strong transactions can also be converted into MongoDB document atomicity through data model setting techniques to avoid strong transactions. You need to describe more clearly what kind of situation you are talking about so that you can judge whether it can be avoided. For the course reservation scenario that I understand, it is not a strong scenario that requires MongoDB, but it is not a scenario that requires RDBMS. So to say whether MongoDB is suitable for use, it is recommended to analyze the specific situation in detail. === Updated on 2017.4.9 === According to the update in the comments, the following additional explanations are made: The requirement of limiting the number of people can be solved using MongoDB’s document atomicity. As far as I understand the registration scenario, it is nothing more than recording who has signed up for which course, how many people have signed up in total, and controlling not to exceed the registration limit. Then the data structure of the course can be designed like this:
In other words, if you search for this course according to the course ID, if the number of applicants is less than the specified number, new applicants will be added, otherwise no changes will be made. So how to judge whether the registration is successful? findAndModifyBy default, the document before modification will be returned (the document after modification can also be returned). So:
Please refer to db.collection.findAndModify() for the usage of findAndModify的用法请参考db.collection.findAndModify()。MongoDB中对一个文档的修改具备原子性,所以不难发现update也可以很好地完成上述任务。关于update和findAndUpdate. Modifications to a document in MongoDB are atomic, so it is not difficult to find that update can also complete the above tasks well. For comparisons between update and findAndUpdate, please refer to: Compares with update Method
MongoDB is not suitable for strong transaction scenarios, but many scenarios often do not require strong transactions, and can be replaced by eventual consistency. Many strong transactions can also be converted into MongoDB document atomicity through data model setting techniques to avoid strong transactions. You need to describe more clearly what kind of situation you are talking about so that you can judge whether it can be avoided.
For the course reservation scenario that I understand, it is not a strong scenario that requires MongoDB, but it is not a scenario that requires RDBMS. So to say whether MongoDB is suitable for use, it is recommended to analyze the specific situation in detail.
=== Updated on 2017.4.9 ===
According to the update in the comments, the following additional explanations are made:
The requirement of limiting the number of people can be solved using MongoDB’s document atomicity. As far as I understand the registration scenario, it is nothing more than recording who has signed up for which course, how many people have signed up in total, and controlling not to exceed the registration limit. Then the data structure of the course can be designed like this:
This course can be updated when someone signs up:
In other words, if you search for this course according to the course ID, if the number of applicants is less than the specified number, new applicants will be added, otherwise no changes will be made. So how to judge whether the registration is successful?
findAndModify
By default, the document before modification will be returned (the document after modification can also be returned). So:Please refer to db.collection.findAndModify() for the usage of
findAndModify
的用法请参考db.collection.findAndModify()。MongoDB中对一个文档的修改具备原子性,所以不难发现update
也可以很好地完成上述任务。关于update
和findAndUpdate
. Modifications to a document in MongoDB are atomic, so it is not difficult to find thatupdate
can also complete the above tasks well. For comparisons betweenupdate
andfindAndUpdate
, please refer to: Compares with update Method