0

I am trying to achieve document level locking in MongoDB3.0 with wiredTiger storage Engine.

What I want to achieve is -> read a document -> lock it -> perform some operation on the data -> store the result in a new document -> unlock the previous document.

Is it possible to do that with pymongo??

Sumit Paliwal
  • 385
  • 1
  • 3
  • 14
  • According to me document level locking is handled by MongoDB. you can directly use pymongo to perform operation and locking and releasing of documents will be handled internally. By default database takes a exclusive lock for write/update but not for read (if you do that database will take a load of very less users than its capacity for reads and it is not practical as well). If this doesn't satisfy you then elaborate your need so that community can provide better alternatives. – Nachiket Kate Nov 09 '15 at 15:57
  • Thanks Nachiket, I understand the solution that is provided by mongodb itself. But my requirement is a little different here. The flow for my problem is in this way Thread1 reads data, from a document... thread2 reads data from same document ..... T1 performs some operations and inserts a new document based on the read value........ T2 also performs some operations and inserts a new document based on the read value..... Here What I want is that T2 should wait untill the T1 writes data... and T2 should read from the new document .... – Sumit Paliwal Nov 12 '15 at 06:08
  • Can't you handle this in application code where you are scheduling threads T1, T2? Check mutex locks if t1 is performing operations then make T2 wait and after t1 finishes then allow T2 to continue. – Nachiket Kate Nov 12 '15 at 17:36
  • @SumitPaliwal have you got any solution? – Naisarg Parmar Oct 11 '21 at 14:36
  • I am also looking for solution for this https://stackoverflow.com/questions/69237272/document-read-and-insert-with-locking-transaction-in-nodejs-with-mongodb – Naisarg Parmar Oct 11 '21 at 14:37

0 Answers0