Read update write integrity

I think Mongo covers this problem, but I’d like to get confirmation.

I have an app that books Warbird flights. A passenger will be displayed the number of seats available and can choose any number up to the displayed limit. The passenger selects one or more, then clicks pay.

Before the seats are booked, I need to make sure that someone else did not buy the seats. If I was coding an SQL database, I would have to lock a flight record, read it and make sure the seats are still available, then if the seats were still available, record the purchase then write the flight record back and release the lock.

According to this stackoverflow: node.js - MongoDB: Lock and unlock collection manually - Stack Overflow MongoDB handles this for me.

Here’s a link to the beta web site


Hi @Jim_Olivi and welcome to the MongoDB community forum!!

Can you confirm if you are seeking a confirmation regarding the post on stackoverflow about how locking works in MongoDB? More specifically, is it confirmation regarding the Answer (posted by Wan B.)?


Thanks for the reply.

Yes, I am looking for a confirmation of the stackoverflow post.

If MongoDB does serialize reads/writes then I don’t have to worry about the integrity of the records.

Lastly: if a record is changed before the initial transaction is completed, what error is raised?

@Jim_Olivi Yes, it’s serialized.

A write conflict occurs, and that write conflict will abort the transaction and retry. If it fails again you’ll get a writeConflict exception.