Z
Z
zogrog2015-03-30 15:53:37
MongoDB
zogrog, 2015-03-30 15:53:37

How to do similar in mongodb?

Good afternoon!
Please tell me how to implement this in mongodb:
locking a key, reading a key, checking the value of a key, possibly changing a key, unlocking a key.
when the connection is broken, the lock is released.
I need to get behavior similar to postgresql behavior: begin; select for update; update; commit;
I need to eliminate the race condition when changing the value of a key.
is this at all possible to do in mongodb?
findAndModify() is not suitable because it is possible that we execute a request and do not receive a response or fall off

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SilentFl, 2015-03-30
@SilentFl

you want a transaction - there are none in monge.
but you can do it like this

L
lega, 2015-03-31
@lega

findAndModify() is not suitable because it is possible that we execute a request and do not receive a response or fall off
You will definitely get an answer if everything went smoothly.
Do you need something to roll back the value when it breaks, or is it enough to remove the lock?
Removing a lock during a break and a crash can be done in different ways:
For example, you can set a lock with a timeout at which the lock will not be active, for example, in a minute, this option is not bad, given that this is a very rare situation (simple disconnects should not affect, they are automatically raised ).
If the first launch is in progress (for example, after a server reboot), then you can simply demolish all the locks.
You can select a separate process that will be responsible for the key / value (may issue 10-30Kops / sec).
You can also come up with options with reference to the process, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question