amit.mevada
amit.mevada

Reputation: 103

mongoDB write is occuring then a read must wait or not wait

When mongoDB write is occurring then a read must wait or not wait. when mongoDB going to write some doc in mongodb at that time write lock happen and other thread try to read other docs then it should wait until write lock release or not. is there any dependency between all read and write locks

Upvotes: 4

Views: 1070

Answers (1)

BatScream
BatScream

Reputation: 19700

From the docs.

MongoDB uses a readers-writer lock that allows concurrent reads access to a database but gives exclusive access to a single write operation.

When a read lock exists, many read operations may use this lock. However, when a write lock exists, a single write operation holds the lock exclusively, and no other read or write operations may share the lock.

Locks are “writer greedy,” which means write locks have preference over reads. When both a read and write are waiting for a lock, MongoDB grants the lock to the write.

To answer your question:

So 'n' number of reads can happen in parallel, and all reads/writes are blocked when a write happens.

Upvotes: 6

Related Questions