Is the course reservation system suitable for mongodb?

  mongodb, question

There is a project of course reservation for users. mongodb is a good choice because node is at the back end. However, due to the transaction operation of course reservation information after successful reservation or cancellation of reservation, my understanding of mongo is that she is not suitable for the transaction scenario. I am not very familiar with the design of the database. Would you like to ask whether mongodb is suitable for such projects as course reservation?

MongoDB is not suitable forStrong transactionThe scene, but many scenes need not really strong transactions, and can be usedFinal consistencyInstead. Many strong transactions can also be transformed into MongoDB’s document atomicity through the techniques of data model setting to avoid strong transactions. You need to describe more clearly what kind of situation you are talking about in order to judge whether it can be avoided.
For the course reservation scenario that I understand myself, it is not a very strong scenario that must be MongoDB, but it is also not a scenario that must be RDBMS. Therefore, whether MongoDB is suitable or not is suggested to be analyzed in specific situations.
=== 2017.4.9 update = = =
According to the update in the commentary, make the following supplementary explanation:
The requirement of limiting the number of people can be solved by MongoDB’s document atomicity. As far as I understand the application scenario, it is nothing more than recording who applied for which course, how many people applied in total, and controlling not to exceed the application limit. Then the data structure of the course can be designed like this:

{
 _id: ObjectId("58e9f6cd58d2c10959c8619a"),
 Title: "MongoDB Getting Started Tutorial ",
 Intro: "for demonstration purposes",
 createdAt: ISODate("2017-04-09T17:00:00Z"),
 createdBy: {
 userId: 12345,
 Name: "MongoDB Chinese Community "
 //Other necessary information
 },
 Allowedattendeeeqty: 50//Number of participants allowed
 reservations: {
 Qty: 0, // Number of Reserved Persons
 Attendees: [123,456,789]/participant ID
 }
 }

When someone signs up, this course can be updated:

var result = db.class.findAndUpdate(
 query: {
 _id: ObjectId("58e9f6cd58d2c10959c8619a"),
 Qty: {$lte: 50} // Only apply when the number of applicants is less than 50
 },
 update: {
 $inc: {
 "reservations.qty": 1 // Enrolment +1
 },
 $push: {
 "reservations.attendees": 102 // ID of new enrollee
 }
 }
 });

In other words, to find this course according to the course ID, when the number of applicants is less than the specified number, new applicants will be added, otherwise no changes will be made. How to judge whether the registration is successful?findAndModifyThe document before modification will be returned by default (the modified document can also be returned). So:

if (result.reservations.qty < 50) {
 //Successful registration
 } else {
 //Registration Failed
 }

AboutfindAndModifyPlease refer to the usage ofdb.collection.findAndModify(). Modifying a document in MongoDB is atomic, so it is not difficult to find itupdateYou can also accomplish the above tasks well. AboutupdateAndfindAndUpdateFor comparison, please refer to:Compares with update Method