MongoDB write happens, then read should wait or not wait

When mongoDB write occurs, read must wait or not wait. when mongoDB is about to write some document to mongodb at this time, a lock write will happen and another thread will try to read other documents, then it should wait until the write lock is released or not. is there any dependency between all read and write locks

+3


source to share


1 answer


From the docs .

MongoDB uses a read-write lock, which allows concurrent read access to the database, but gives exclusive access to a single write operation.

When a read lock exists, many read operations can use that lock. However, when a write lock exists, a single write contains locks exclusively, and no other read or write can lock.

Greedy writers, which means that write locks take precedence over read locks. When both reads and writes are waiting for a lock, MongoDB grants a write lock.



To answer your question:

Thus, the number of reads can occur in parallel, and all reads / writes are blocked when writing writes.

+3


source







All Articles