R
R
razoronline2015-03-04 20:12:53
NoSQL
razoronline, 2015-03-04 20:12:53

Why/when to use Mongodb (document/collection level) blocking?

I just read on Habré about the release of Mongodb 3. There is a novelty there - locking at the document level, before that it was at the collection level.
In the DB world, I'm not a professional. I would like to understand why and when you need to use a lock (no matter at what level). And what is the advantage of locking at the document level than at the collection level.
Already googled. I didn't find a simple answer. Please someone please enlighten me.
Thanks in advance

Answer the question

In order to leave comments, you need to log in

4 answer(s)
K
kazmiruk, 2015-03-05
@kazmiruk

When you make changes to a record, the database locks that record so that no one else gets in and starts trying to change something too. If she does not do this, then bugs will inevitably go. So, when this was done at the level of collections, then when one record was changed, the entire collection containing the record was blocked. And even if you try to change a completely different record, you still have to wait for the previous lock. Those. accessing the entire collection was synchronous 1 record at a time. Now only the document being manipulated is blocked. This allows 10 different users to work on 10 different documents in the collection at the same time and not wait for each other, which significantly increases the speed of response.

A
Alexander, 2015-03-04
@disc

When the lock is on an entire collection, you cannot modify any document in that collection.
If at the document level, you can safely and without deadlocks change other documents in the collection.

R
Ruslan Abdullaev, 2015-03-04
@rajdee

The issue of locking arises when a resource is accessed simultaneously, i.e. in previous versions of MongoDB, the entire collection was locked when accessed simultaneously, but in the new version, only the document.

A
Aristarkh Zagorodnikov, 2015-03-07
@onyxmaster

A small clarification - before 3.0 (2.8) the lock was at the database level, not the collection. In the new version, locks depend on the storage engine used. File-compatible storage engine MMAPv1 now supports collection-level locks, and the new WiredTiger storage engine supports document-level locking (actually not exactly documents, but records, but in general you can say so).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question