<?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: MD. Nur Islam</title>
    <description>The latest articles on DEV Community by MD. Nur Islam (@nurthedev).</description>
    <link>https://dev.to/nurthedev</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%2F3558610%2F552e5a42-e005-4056-a34b-a6cdf66b98cc.jpeg</url>
      <title>DEV Community: MD. Nur Islam</title>
      <link>https://dev.to/nurthedev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nurthedev"/>
    <language>en</language>
    <item>
      <title>🧩 Mastering MongoDB startSession() — The Key to Reliable Transactions</title>
      <dc:creator>MD. Nur Islam</dc:creator>
      <pubDate>Sat, 01 Nov 2025 05:55:09 +0000</pubDate>
      <link>https://dev.to/nurthedev/mastering-mongodb-startsession-the-key-to-reliable-transactions-3j6d</link>
      <guid>https://dev.to/nurthedev/mastering-mongodb-startsession-the-key-to-reliable-transactions-3j6d</guid>
      <description>&lt;h1&gt;
  
  
  🧩 Mastering MongoDB startSession() — The Key to Reliable Transactions
&lt;/h1&gt;

&lt;p&gt;When working with &lt;strong&gt;MongoDB&lt;/strong&gt;, especially in production environments, maintaining &lt;strong&gt;data consistency&lt;/strong&gt; is crucial.  &lt;/p&gt;

&lt;p&gt;Imagine creating an order and updating user data at the same time — if one operation fails, the other shouldn’t be saved either. That’s where &lt;strong&gt;sessions&lt;/strong&gt; and &lt;strong&gt;transactions&lt;/strong&gt; come into play.  &lt;/p&gt;

&lt;p&gt;Let’s break it down 👇  &lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 What is a Session in MongoDB?
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;session&lt;/strong&gt; in MongoDB is like a container that groups multiple operations together so they behave as one unit.  &lt;/p&gt;

&lt;p&gt;Think of it as a “safe box” — all operations inside are either &lt;strong&gt;fully saved&lt;/strong&gt; or &lt;strong&gt;fully canceled&lt;/strong&gt;.  &lt;/p&gt;

&lt;h3&gt;
  
  
  In short:
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;A MongoDB session allows you to run a set of operations as a single transaction — ensuring all-or-nothing data consistency.  &lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  ⚙️ What is &lt;code&gt;startSession()&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;startSession()&lt;/code&gt; is a method used to &lt;strong&gt;create a new session&lt;/strong&gt; in MongoDB.&lt;br&gt;&lt;br&gt;
Once you start a session, you can perform multiple operations and commit or abort them together.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mongoose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mongoose&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;runTransaction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;session&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;mongoose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startSession&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Start session&lt;/span&gt;

  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startTransaction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Begin transaction&lt;/span&gt;

    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;([{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}],&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;session&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;([{&lt;/span&gt; &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt; &lt;span class="p"&gt;}],&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;session&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;commitTransaction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Save all changes&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;✅ Transaction committed successfully!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abortTransaction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Roll back everything&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;❌ Transaction aborted:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;finally&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;endSession&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Close the session&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;runTransaction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  🧩 How It Works (Step-by-Step)
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Start a Session → mongoose.startSession()&lt;/li&gt;
&lt;li&gt;Start a Transaction → session.startTransaction()&lt;/li&gt;
&lt;li&gt;Perform Operations → Execute multiple create, update, or delete actions&lt;/li&gt;
&lt;li&gt;Commit or Abort → Save all with commitTransaction() or undo all with abortTransaction()&lt;/li&gt;
&lt;li&gt;End the Session → Always close it with endSession()&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  📊 Visual Flow
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Start Session
     ↓
Start Transaction
     ↓
Execute Multiple Operations
     ↓
Commit ✅ or Abort ❌
     ↓
End Session
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  🚀 When to Use Transactions
&lt;/h2&gt;

&lt;p&gt;Use MongoDB transactions when you need data integrity across multiple operations or collections.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Use Cases:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🛒 E-commerce checkout: update order + user balance&lt;/li&gt;
&lt;li&gt;🏦 Banking systems: transfer between two accounts&lt;/li&gt;
&lt;li&gt;🧾 Inventory management: update stock + order log&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;They ensure that if one step fails, the entire operation rolls back — leaving your database consistent.&lt;/p&gt;

&lt;h2&gt;
  
  
  ⚠️ Important Notes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Transactions only work in environments that support replica sets (MongoDB Atlas already has this).&lt;/li&gt;
&lt;li&gt;Avoid transactions for single-document operations (MongoDB handles those atomically by default).&lt;/li&gt;
&lt;li&gt;Always handle errors properly and close the session to free resources.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  💡 Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Mastering startSession() is an important step toward writing reliable and production-grade backend code.&lt;br&gt;
It ensures that your database operations stay consistent — no partial updates, no mismatched records.&lt;/p&gt;

&lt;p&gt;If you’ve ever faced issues with half-saved data or failed updates, sessions and transactions are your best friends.&lt;br&gt;
Use them wisely and make your backend bulletproof 🔐&lt;/p&gt;

</description>
      <category>mongodb</category>
      <category>backend</category>
      <category>database</category>
      <category>mern</category>
    </item>
    <item>
      <title>🔐 Understanding Access Tokens and Refresh Tokens (Made Simple for Developers)</title>
      <dc:creator>MD. Nur Islam</dc:creator>
      <pubDate>Mon, 27 Oct 2025 04:43:23 +0000</pubDate>
      <link>https://dev.to/nurthedev/understanding-access-tokens-and-refresh-tokens-made-simple-for-developers-5bfg</link>
      <guid>https://dev.to/nurthedev/understanding-access-tokens-and-refresh-tokens-made-simple-for-developers-5bfg</guid>
      <description>&lt;h1&gt;
  
  
  🔐 Understanding Access Tokens and Refresh Tokens (Made Simple for Developers)
&lt;/h1&gt;

&lt;p&gt;If you’ve ever used a modern app — whether it’s logging into Netflix, Spotify, or even GitHub — you’ve already been working with &lt;strong&gt;access tokens&lt;/strong&gt; and &lt;strong&gt;refresh tokens&lt;/strong&gt;… even if you didn’t know it. 😄  &lt;/p&gt;

&lt;p&gt;Let’s break them down 👇  &lt;/p&gt;




&lt;h2&gt;
  
  
  ✅ Access Token
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🕒 &lt;strong&gt;Short-lived “entry pass”&lt;/strong&gt; for APIs or protected routes
&lt;/li&gt;
&lt;li&gt;📤 Sent with every request to prove authorization
&lt;/li&gt;
&lt;li&gt;⏳ &lt;strong&gt;Expires quickly&lt;/strong&gt; (usually in minutes or hours) to enhance security
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of it as your &lt;strong&gt;temporary badge&lt;/strong&gt; for entering restricted areas of an app.  &lt;/p&gt;




&lt;h2&gt;
  
  
  ✅ Refresh Token
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🔁 &lt;strong&gt;Long-lived secret&lt;/strong&gt; used to get a new access token when it expires
&lt;/li&gt;
&lt;li&gt;🚫 Not sent with every request — only used when the access token is invalid
&lt;/li&gt;
&lt;li&gt;📅 Has a longer lifespan (days, weeks, or even months)
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s what keeps you logged in &lt;em&gt;without&lt;/em&gt; needing to type your password every few minutes.  &lt;/p&gt;




&lt;h2&gt;
  
  
  🤔 Why Do We Need Both?
&lt;/h2&gt;

&lt;p&gt;Using both tokens together creates a balance between &lt;strong&gt;security&lt;/strong&gt; and &lt;strong&gt;user experience&lt;/strong&gt;:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🔒 &lt;strong&gt;Security:&lt;/strong&gt; Short-lived access tokens reduce damage if stolen.
&lt;/li&gt;
&lt;li&gt;😌 &lt;strong&gt;Convenience:&lt;/strong&gt; Refresh tokens allow users to stay logged in seamlessly.
&lt;/li&gt;
&lt;li&gt;⚡ &lt;strong&gt;Performance:&lt;/strong&gt; Reduces the need for full authentication on every request.
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🎟 Real-World Analogy
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Access Token&lt;/strong&gt; → 🎟 &lt;em&gt;Movie ticket&lt;/em&gt; (valid for one show).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Refresh Token&lt;/strong&gt; → 🎫 &lt;em&gt;VIP pass&lt;/em&gt; (lets you get a new ticket without buying again).
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Simple, right?  &lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Security Tips for Developers
&lt;/h2&gt;

&lt;p&gt;When implementing token-based authentication:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;🧱 Store &lt;strong&gt;refresh tokens&lt;/strong&gt; securely — use &lt;strong&gt;HTTP-only cookies&lt;/strong&gt; in browsers.
&lt;/li&gt;
&lt;li&gt;🔄 Rotate tokens regularly and revoke old ones.
&lt;/li&gt;
&lt;li&gt;🌐 Always use &lt;strong&gt;HTTPS&lt;/strong&gt; to prevent token interception.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These practices ensure your app remains both &lt;strong&gt;safe&lt;/strong&gt; and &lt;strong&gt;user-friendly&lt;/strong&gt;.  &lt;/p&gt;




&lt;h2&gt;
  
  
  🧩 TL;DR
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Access Token:&lt;/strong&gt; short-term security 🔐&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Refresh Token:&lt;/strong&gt; long-term convenience 🔁  &lt;/p&gt;

&lt;p&gt;Together, they keep your system &lt;strong&gt;secure&lt;/strong&gt; and your users &lt;strong&gt;happy&lt;/strong&gt; 💪  &lt;/p&gt;




&lt;p&gt;💬 Have you implemented access &amp;amp; refresh token flows in your projects yet?&lt;br&gt;&lt;br&gt;
Drop your thoughts or experience below 👇 — let’s help more devs understand real-world authentication!  &lt;/p&gt;

</description>
      <category>node</category>
      <category>jwt</category>
      <category>beginners</category>
      <category>security</category>
    </item>
    <item>
      <title>🚫 Dopamine Detox - How I Rewired My Brain for Focus 💻</title>
      <dc:creator>MD. Nur Islam</dc:creator>
      <pubDate>Sun, 19 Oct 2025 04:36:37 +0000</pubDate>
      <link>https://dev.to/nurthedev/dopamine-detox-how-i-rewired-my-brain-for-focus-553j</link>
      <guid>https://dev.to/nurthedev/dopamine-detox-how-i-rewired-my-brain-for-focus-553j</guid>
      <description>&lt;p&gt;&lt;strong&gt;🚫 Dopamine Detox - How I Rewired My Brain for Focus 💻&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flmo5komlnz3kgkd0qsru.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flmo5komlnz3kgkd0qsru.png" alt=" " width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Recently, I finished reading "Dopamine Detox" by Thibaut Meurisse - and honestly, it hit me hard.&lt;br&gt;
 As a developer, I realized that I wasn't just battling bugs or code errors… I was battling distractions.&lt;br&gt;
Every time I'd check my phone "just for a minute," scroll through YouTube, or jump between tabs, I was unknowingly training my brain for instant rewards - not deep focus.&lt;br&gt;
 And that's what dopamine detox helped me understand.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🧠 What I Learned&lt;/strong&gt;&lt;br&gt;
1️⃣ Dopamine isn't pleasure - it's anticipation.&lt;br&gt;
 It's that "ping" when you get a message or a new notification. It's the constant craving for more.&lt;br&gt;
 But this endless loop kills long-term focus - something every developer depends on.&lt;br&gt;
2️⃣ Overstimulation is the silent productivity killer.&lt;br&gt;
 When your brain is overloaded with small hits of dopamine (social media, music, multitasking), even simple work starts to feel boring.&lt;br&gt;
 I used to open my IDE but end up refreshing GitHub or Discord instead of writing actual code.&lt;br&gt;
3️⃣ Focus feels boring - until it feels peaceful.&lt;br&gt;
 During my detox, I avoided all unnecessary stimulation: no YouTube, no music, no endless scrolling.&lt;br&gt;
 At first, it was painful. But then… silence became clarity. I started thinking again - not just reacting.&lt;br&gt;
4️⃣ Boredom is the gateway to creativity.&lt;br&gt;
 When I stopped constantly feeding my brain, new ideas appeared naturally.&lt;br&gt;
 I got more excited about small progress - fixing one bug, improving one UI - instead of chasing constant excitement.&lt;br&gt;
5️⃣ Systems &amp;gt; Motivation.&lt;br&gt;
 The book's biggest lesson for me: focus isn't about willpower. It's about environment design.&lt;/p&gt;

&lt;p&gt; So now, I:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Keep my phone in another room when coding.&lt;/li&gt;
&lt;li&gt;Start my day with a single "deep work" session before touching the internet.&lt;/li&gt;
&lt;li&gt;Use "closed systems" (like my code editor or terminal) instead of open distractions (like YouTube or Facebook).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;💡 My Takeaway&lt;/strong&gt;&lt;br&gt;
A dopamine detox isn't about quitting joy - it's about regaining control.&lt;br&gt;
 It's about teaching your brain that focus, calm, and creation are far more rewarding than instant hits of pleasure.&lt;br&gt;
As developers, our real power lies in deep work - solving problems, building ideas, and staying consistent when it's not exciting.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🧭 If You're Feeling Distracted Lately…&lt;/strong&gt;&lt;br&gt;
Try this for 24 hours:&lt;br&gt;
Avoid all unnecessary notifications&lt;br&gt;
No YouTube or social media&lt;br&gt;
Do one focused task (even a small one)&lt;/p&gt;

&lt;p&gt;You'll notice how quiet your mind becomes - and how sharp your focus feels.&lt;br&gt;
💬 Question for you:&lt;br&gt;
 Have you ever tried a dopamine detox? Or felt your attention slipping because of too many screens?&lt;br&gt;
 Would love to hear your thoughts 👇&lt;/p&gt;

</description>
      <category>dopaminedetox</category>
      <category>programming</category>
      <category>productivity</category>
      <category>career</category>
    </item>
  </channel>
</rss>
