<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kailashnath Nagendran</title>
    <description>The latest articles on DEV Community by Kailashnath Nagendran (@kailashnath1998).</description>
    <link>https://dev.to/kailashnath1998</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F392992%2F18ca4a13-4bb1-480d-8ba7-901e6a184de9.jpeg</url>
      <title>DEV Community: Kailashnath Nagendran</title>
      <link>https://dev.to/kailashnath1998</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kailashnath1998"/>
    <language>en</language>
    <item>
      <title>Atomic Transactions in MongoDB With NodeJS</title>
      <dc:creator>Kailashnath Nagendran</dc:creator>
      <pubDate>Fri, 22 May 2020 16:07:06 +0000</pubDate>
      <link>https://dev.to/kailashnath1998/atomic-transactions-in-mongodb-with-nodejs-47o2</link>
      <guid>https://dev.to/kailashnath1998/atomic-transactions-in-mongodb-with-nodejs-47o2</guid>
      <description>&lt;p&gt;Atomic Transactions are very useful when one has to perform a indivisible and irreducible series of database operations, and with mongoDB the multi document atomic transactions were introduced in the version 4.0. While MongoDb is wiidely used along with NodeJS, I thought it would be helpful to have an example of performing atomic transactions in mongodb with nodejs.&lt;/p&gt;

&lt;p&gt;MongoDB atomic transactions with NodeJS&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var mongoose = require('mongoose');

async () =&amp;gt; {
    const session = await mongoose.startSession();
    await session.startTransaction();
    try {
        const opts = { session, new: true };
        // perform operations
     } catch (error) {
        await session.abortTransaction();
        await session.endSession();
        throw error;
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Important things to remember:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Every transaction has a session associated with it&lt;/li&gt;
&lt;li&gt;At a given time, at most only one open transaction for a session.&lt;/li&gt;
&lt;li&gt;If a session ends and it has an open transaction, the transaction aborts.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>node</category>
      <category>npm</category>
      <category>mongodb</category>
    </item>
  </channel>
</rss>
