How should I handle concurrency in mongodb? -


i working on web service writing data records mongodb. service reads document mongodb, performs calculations , updates data in document , overwrites document mongodb. need make sure before write data mongodb, no other process has updated document, otherwise may experience data loss when replacing document. how can ensure data integrity @ application level? can lock document while performing calculations? should check version number on document before replacing document? strategies industry uses handle situations this? in advance

you can query value in document updated part of call update() check document still in state expect, , confirm no-one else updated since last read document. similar optimistic lock approach. see https://docs.mongodb.com/manual/core/write-operations-atomicity/#concurrency-control


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -