{"id":6102,"date":"2014-04-13T02:23:41","date_gmt":"2014-04-13T02:23:41","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/13\/mongodb-c-driver-update-multiple-documents-in-one-atomic-operation-collection-of-common-programming-errors\/"},"modified":"2014-04-13T02:23:41","modified_gmt":"2014-04-13T02:23:41","slug":"mongodb-c-driver-update-multiple-documents-in-one-atomic-operation-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/13\/mongodb-c-driver-update-multiple-documents-in-one-atomic-operation-collection-of-common-programming-errors\/","title":{"rendered":"MongoDb c# driver update multiple documents in one atomic operation-Collection of common programming errors"},"content":{"rendered":"<p>I want to ask you if the following code will be executed in one atomic operation. I&#8217;m using mongodb c# driver.<\/p>\n<p>The input to the method is list of id of the objects I want to update.<\/p>\n<pre><code>public void Update(IEnumerable ids)\n{\n    var query = Query.Where(t =&gt; ids.Contains(t.Id));\n    var update = Update.Set(\"Modified\", DateTime.Now); \/\/this is just example of update\n\n    var options = new MongoUpdateOptions {Flags = UpdateFlags.Multi};\n\n    Collection.Update(query, update, options);\n}\n<\/code><\/pre>\n<p>I&#8217;m interesting about the case, when I have milions of documents to update. What will happen if there will be a fail (power or hardware problem) during this update? Will be the database in a consistent state?<\/p>\n<p>thanks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I want to ask you if the following code will be executed in one atomic operation. I&#8217;m using mongodb c# driver. The input to the method is list of id of the objects I want to update. public void Update(IEnumerable ids) { var query = Query.Where(t =&gt; ids.Contains(t.Id)); var update = Update.Set(&#8220;Modified&#8221;, DateTime.Now); \/\/this is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6102","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6102","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6102"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6102\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6102"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6102"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}