from name findoneandupdate()
understand atomic operation.
what if want find 10 items (limit(10)) , update them alike?
example set state field "in progress"?
is atomically achievable mongodb? there built-in functionality in c# driver maybe? don't want implement 2pc myself if avoidable :-) have other consumers asking documents well, therefore want avoid double processing although not critical business case.
the motivation not use findoneandupdate()
10 times purely networking (less chatter, , better performance) related. not have requirement transaction-like behavior.
the database nor business case under control told expect many documents going in , out rather quickly.
in mongodb, operations considered atomic on per-document basis. is, if update multiple fields in document single update statement, of updates or none of them should queried while update happening. means update affects more 1 document not atomic operation across documents, atomic within document.
since sounds concerned being more efficient sending commands server, not whether or not operation atomic server side, can use bulkwriteasync()
takes ienumerable<writemodel<tdocument>>
of updates perform on server.
this allows build list updates , execute them in 1 operation server. care must taken during process handle failed writes. take @ mongodb docs on over here.
Comments
Post a Comment