<?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: Hemanth Babu</title>
    <description>The latest articles on DEV Community by Hemanth Babu (@hemanthbabu164_76).</description>
    <link>https://dev.to/hemanthbabu164_76</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%2F3268996%2Fba86db7e-1e14-4b67-abc9-17faa83d2e27.jpeg</url>
      <title>DEV Community: Hemanth Babu</title>
      <link>https://dev.to/hemanthbabu164_76</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hemanthbabu164_76"/>
    <language>en</language>
    <item>
      <title>🎪Kafka Without the Zoo: Should You Go KRaft Mode?</title>
      <dc:creator>Hemanth Babu</dc:creator>
      <pubDate>Mon, 14 Jul 2025 14:01:24 +0000</pubDate>
      <link>https://dev.to/hemanthbabu164_76/kafka-without-the-zoo-should-you-go-kraft-mode-3ko2</link>
      <guid>https://dev.to/hemanthbabu164_76/kafka-without-the-zoo-should-you-go-kraft-mode-3ko2</guid>
      <description>&lt;h3&gt;
  
  
  ✅ TL;DR
&lt;/h3&gt;

&lt;p&gt;Kafka’s new KRaft mode removes Zookeeper, simplifies architecture, speeds failover, improves metadata consistency, and preps you for massive scale—worth the migration if you're ready for the next generation of Kafka.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Intro – What’s Cooking with Kafka?&lt;/strong&gt;&lt;br&gt;
Imagine you’re building a food-ordering app—orders flood in, must be queued, routed, and reliably stored. Kafka stands behind the scenes like a high-speed restaurant order line. But until recently, you needed another service—Zookeeper—to manage who’s cooking what. Now Kafka has learned to handle things solo with &lt;strong&gt;KRaft&lt;/strong&gt;. So… what’s the deal?&lt;/p&gt;




&lt;h2&gt;
  
  
  🧐 Quick Kafka Recap
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Producer&lt;/strong&gt; = kitchen staff placing orders (messages)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Topic&lt;/strong&gt; = menu (e.g., "pizza-orders")&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Partition&lt;/strong&gt; = individual order queueline&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consumer&lt;/strong&gt; = delivery staff pulling orders&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Broker&lt;/strong&gt; = kitchen station storing your orders&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Offset&lt;/strong&gt; = tracker of what’s been cooked (read by consumers)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Kafka handles streaming data like a champ—millions of messages per second—often in real-time 🔥&lt;/p&gt;




&lt;h2&gt;
  
  
  🏛️ The Old Way: Kafka + Zookeeper
&lt;/h2&gt;

&lt;p&gt;Think of &lt;strong&gt;Zookeeper&lt;/strong&gt; as Kafka’s maître d’—manages metadata, broker leader elections, and keeps the whole place synchronized.&lt;/p&gt;

&lt;h3&gt;
  
  
  What It Does:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Keeps track of topic layouts, partitions, replicas, and who’s boss&lt;/li&gt;
&lt;li&gt;Elects broker leaders and handles failovers&lt;/li&gt;
&lt;li&gt;Ensures everyone agrees (consistency &amp;amp; metadata coordination)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Zoo Problems:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Double ops&lt;/strong&gt;: you now manage Kafka + ZK—extra overhead&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scaling pains&lt;/strong&gt;: Zookeeper can choke under heavy metadata load&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Laggy updates&lt;/strong&gt;: slow metadata changes can cause stale reads&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Timeout hiccups&lt;/strong&gt;: delays can yield frustrating request timeouts&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Classic case: you fix Kafka, but ZK chokes—and nothing works. 😬&lt;/p&gt;




&lt;h2&gt;
  
  
  🌟 The New Hotness: Kafka + KRaft
&lt;/h2&gt;

&lt;p&gt;Enter KRaft ("Kafka Raft Metadata Mode"), Kafka’s new internal conductor—no Zookeeper required.&lt;/p&gt;

&lt;h3&gt;
  
  
  How It Works:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Metadata lives in a Kafka-internal topic&lt;/li&gt;
&lt;li&gt;Controller nodes form a &lt;strong&gt;quorum&lt;/strong&gt; for high availability&lt;/li&gt;
&lt;li&gt;Leaders are elected via &lt;strong&gt;Raft&lt;/strong&gt;—Kafka’s own internal election&lt;/li&gt;
&lt;li&gt;Brokers and controllers are unified—no external components&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Benefits of Going KRaft:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;🔄 Simplicity&lt;/strong&gt;: One stack, one config, no zoo to feed&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;⚡ Speedy failover&lt;/strong&gt;: metadata leader swaps in milliseconds&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;📈 Scale-friendly&lt;/strong&gt;: handles millions of partitions easily&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;✏️ Consistency&lt;/strong&gt;: shared log ensures all nodes agree&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;⚙️ Operational efficiency&lt;/strong&gt;: faster topic changes, less overhead&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;🧪 KRaft mode has been &lt;strong&gt;production-ready since Kafka 3.3+&lt;/strong&gt;, and it's expected to become the &lt;strong&gt;default mode in future releases&lt;/strong&gt;. If you're starting fresh, it's the future-proof choice.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🤷 What You Gain—and What You Might Trade
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Zookeeper Setup&lt;/th&gt;
&lt;th&gt;KRaft Setup&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Architecture&lt;/td&gt;
&lt;td&gt;Kafka + external ZK&lt;/td&gt;
&lt;td&gt;Kafka alone&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Setup complexity&lt;/td&gt;
&lt;td&gt;2 clusters, 2 configs&lt;/td&gt;
&lt;td&gt;Just Kafka&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Failover speed&lt;/td&gt;
&lt;td&gt;Moderate (dependent on ZK)&lt;/td&gt;
&lt;td&gt;Milliseconds&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Metadata updates&lt;/td&gt;
&lt;td&gt;Slower, prone to delays&lt;/td&gt;
&lt;td&gt;Fast &amp;amp; consistent&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Scalability&lt;/td&gt;
&lt;td&gt;Hobbled by ZK limits&lt;/td&gt;
&lt;td&gt;Ready for millions of partitions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Migration effort&lt;/td&gt;
&lt;td&gt;Noisy&lt;/td&gt;
&lt;td&gt;Must reconfigure &amp;amp; migrate&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  ☕ Real-World Café Example
&lt;/h2&gt;

&lt;p&gt;In our food app:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;With &lt;strong&gt;Zookeeper&lt;/strong&gt;, launching a new “coffee-orders” topic meant flipping switches in two places (Kafka + ZK), with occasional delays.&lt;/li&gt;
&lt;li&gt;With &lt;strong&gt;KRaft&lt;/strong&gt;, it’s just Kafka—order up: topic live instantly, with no extra coordination.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🚦 Should You Make the Jump?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Go KRaft if you want:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A simpler, more scalable Kafka setup&lt;/li&gt;
&lt;li&gt;Quicker metadata updates and leader elections&lt;/li&gt;
&lt;li&gt;Fewer moving parts to manage&lt;/li&gt;
&lt;li&gt;Future-proofing (KRaft is Kafka’s strategic direction)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Stick with Zookeeper if you:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Already have stable ZK-managed clusters&lt;/li&gt;
&lt;li&gt;Don’t want migration overhead just yet&lt;/li&gt;
&lt;li&gt;Need tested compatibility with older Kafka tools&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🛠️ Migration Tips (High-Level)
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Plan a migration window&lt;/strong&gt; — test in staging&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Export metadata&lt;/strong&gt; from existing cluster&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Boot a KRaft-only cluster&lt;/strong&gt; with the same metadata&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test thoroughly&lt;/strong&gt; (failovers, topic ops, partition splits)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cut-over when confident&lt;/strong&gt; — tell clients to switch&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;(No need for fancy diagrams—just plan, test, and go.)&lt;/p&gt;




&lt;h2&gt;
  
  
  🧭 Final Takeaway
&lt;/h2&gt;

&lt;p&gt;Kafka with Zookeeper has been a reliable combo for years—but it’s time to retire the zoo. KRaft brings simplicity, speed, and future readiness. If you’re standing up a new cluster—or gearing up for scale—go KRaft. It’s not just Kafka under the hood—it’s Kafka leveled up.&lt;/p&gt;

</description>
      <category>kafka</category>
      <category>eventdriven</category>
      <category>streamprocessing</category>
      <category>dataengineering</category>
    </item>
    <item>
      <title>🧠 How I Won a Hackathon With AI as My Entire Dev Team</title>
      <dc:creator>Hemanth Babu</dc:creator>
      <pubDate>Sat, 05 Jul 2025 05:31:54 +0000</pubDate>
      <link>https://dev.to/hemanthbabu164_76/how-i-won-a-hackathon-with-ai-as-my-entire-dev-team-2fgk</link>
      <guid>https://dev.to/hemanthbabu164_76/how-i-won-a-hackathon-with-ai-as-my-entire-dev-team-2fgk</guid>
      <description>&lt;h2&gt;
  
  
  🧠 How I Won a Hackathon With AI as My Entire Dev Team
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🏁 Two apps, built in parallel, done in 45 mins&lt;/li&gt;
&lt;li&gt;💬 ChatGPT acted as my prompt engineer&lt;/li&gt;
&lt;li&gt;🤖 GitHub Copilot (Claude Sonnet 4) handled everything from UI to backend to test scripts&lt;/li&gt;
&lt;li&gt;🛠️ I just orchestrated: feeding prompts, reviewing code, nudging when needed&lt;/li&gt;
&lt;li&gt;🏆 Finished first — still waiting on the prize 👀&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;




&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The Setup:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Internal hackathon. Two app-building challenges.&lt;br&gt;&lt;br&gt;
Everyone geared up to use GitHub Copilot.&lt;br&gt;&lt;br&gt;
I decided to do what I do best:&lt;br&gt;&lt;br&gt;
Let the AI agents take the wheel, while I just asked good questions..&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  📋 The Hackathon Brief
&lt;/h2&gt;

&lt;p&gt;The event was part of an internal initiative on AI-assisted development — specifically around GitHub Copilot. After a few sessions on "Community of Practice," the hackathon was announced as a way to put those ideas to the test.&lt;/p&gt;

&lt;p&gt;Two challenges. Everyone gets the same brief. Fastest (and cleanest) implementation wins.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔧 Challenge 1: Shopping Cart
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;REST API for automobile parts (search, detail, pagination)&lt;/li&gt;
&lt;li&gt;Shopping cart: add/remove items, calculate totals&lt;/li&gt;
&lt;li&gt;Frontend: list view, product detail view, filters&lt;/li&gt;
&lt;li&gt;(Bonus): Price slicer, modern UI&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  📋 Challenge 2: Interactive To-Do List App
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Add, edit, delete tasks&lt;/li&gt;
&lt;li&gt;Categorize by type (work, personal, etc.)&lt;/li&gt;
&lt;li&gt;Due dates, reminders, priorities&lt;/li&gt;
&lt;li&gt;Search and filter by any field&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧙 Enter the Prompt Engineer
&lt;/h2&gt;

&lt;p&gt;I didn’t dive into code — I fired up ChatGPT.&lt;/p&gt;

&lt;p&gt;I keep a dedicated chat I call my &lt;strong&gt;Prompt Engineer&lt;/strong&gt; — it helps me generate perfect prompts for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Building full apps&lt;/li&gt;
&lt;li&gt;Debugging errors&lt;/li&gt;
&lt;li&gt;Generating role/personality setups (e.g. for ChatGPT agents)&lt;/li&gt;
&lt;li&gt;Image generation (like with Sora)&lt;/li&gt;
&lt;li&gt;Styling or scripting tweaks — you name it&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So naturally, I gave it both challenge descriptions and asked:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💬 “Give me a prompt for Copilot to build this functionality (Challenge 1). I like Python, but suggest the best stack.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then the same for Challenge 2.&lt;/p&gt;

&lt;p&gt;In return, I got two perfectly structured prompts — ready to feed into GitHub Copilot’s agent chat.&lt;/p&gt;

&lt;p&gt;My job? Just passing messages between two AIs.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;📊 Here’s how the flow looked in practice:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&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%2Fu0fvsj2nn7fxe0rzvk39.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%2Fu0fvsj2nn7fxe0rzvk39.png" alt="AI Orchestration Flow" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;From requirements to results — one prompt at a time.&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚡ Copilot (Claude Sonnet 4) Gets to Work
&lt;/h2&gt;

&lt;p&gt;I pasted the prompts into &lt;strong&gt;GitHub Copilot Chat (Agent Mode)&lt;/strong&gt; — which runs on &lt;strong&gt;Claude Sonnet 4&lt;/strong&gt; — and sat back.&lt;/p&gt;

&lt;p&gt;And just like that, my AI dev team clocked in. And then the magic began.&lt;/p&gt;




&lt;h3&gt;
  
  
  ✅ The To-Do List App: Done in 10 Minutes
&lt;/h3&gt;

&lt;p&gt;Copilot spun up:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Full frontend and backend&lt;/li&gt;
&lt;li&gt;Batch scripts to launch it&lt;/li&gt;
&lt;li&gt;Markdown documentation (usage, features, setup)&lt;/li&gt;
&lt;li&gt;Even test scripts&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I didn’t write a single line of code.&lt;/p&gt;

&lt;p&gt;It even opened a browser window &lt;em&gt;inside VS Code&lt;/em&gt; to preview the app. Don’t ask me how.&lt;/p&gt;




&lt;h3&gt;
  
  
  🛒 The Shopping Cart: Completed in 45 Minutes
&lt;/h3&gt;

&lt;p&gt;While the To-Do app wrapped itself up, the Shopping Cart took a bit longer — but not by my hand.&lt;/p&gt;

&lt;p&gt;Copilot generated everything:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;API endpoints&lt;/li&gt;
&lt;li&gt;Paginated product listing&lt;/li&gt;
&lt;li&gt;Cart add/remove&lt;/li&gt;
&lt;li&gt;Total price calculation&lt;/li&gt;
&lt;li&gt;Markdown docs, test files, batch scripts — the full package&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There was a small hiccup: clicking a product didn't show its detail view. I pointed it out, and it fixed itself.&lt;/p&gt;

&lt;p&gt;Another bug threw an error. I didn’t even read it — I just asked &lt;strong&gt;ChatGPT Prompt Engineer&lt;/strong&gt; to generate a fix prompt for Copilot. Boom. Fixed.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Honestly, it might have wrapped up even faster if it didn’t insist on writing the README, tests, and startup scripts too.&lt;br&gt;
But I wasn’t complaining — it was like having a junior dev who cares too much about clean handoffs.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  ⏱️ Total Human Effort: 45 Minutes, 0 Code, 100% Prompts
&lt;/h2&gt;

&lt;p&gt;From problem statement to working apps — Copilot did it all.&lt;/p&gt;

&lt;p&gt;The only thing I did manually was manage the flow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Asked ChatGPT for smart prompts&lt;/li&gt;
&lt;li&gt;Fed those to Copilot&lt;/li&gt;
&lt;li&gt;Gave feedback and nudges&lt;/li&gt;
&lt;li&gt;Watched the apps build themselves&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It felt like &lt;strong&gt;prompt-driven programming&lt;/strong&gt; — not software development as we know it.&lt;/p&gt;




&lt;h2&gt;
  
  
  🏆 I Finished First (Still Waiting on the Prize)
&lt;/h2&gt;

&lt;p&gt;By the end of the session, both challenges were:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fully working&lt;/li&gt;
&lt;li&gt;Documented&lt;/li&gt;
&lt;li&gt;Tested&lt;/li&gt;
&lt;li&gt;Launch-ready&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I submitted, wrapped up, and sat back while others were still midway.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“What is the prize?”&lt;br&gt;&lt;br&gt;
They said goodies are coming.&lt;br&gt;&lt;br&gt;
Still waiting. 🫠&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  💡 What This Experience Proves
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;AI isn't just co-pilot — it's a team, if you prompt it well&lt;/li&gt;
&lt;li&gt;You can orchestrate entire apps with structured instructions&lt;/li&gt;
&lt;li&gt;Prompt engineering is a &lt;strong&gt;real skill&lt;/strong&gt; — and a dev superpower&lt;/li&gt;
&lt;li&gt;You don’t need to write code to ship quality software&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This wasn’t cheating — it was &lt;strong&gt;effective orchestration&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔗 Want to Peek Inside?
&lt;/h2&gt;

&lt;p&gt;Here are the links to both repos — explore the code, docs, and flow if you're curious:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🔗 &lt;a href="https://github.com/hemanthbabu164/My-Projects/tree/master/VibeCoded-Projects/todo-list" rel="noopener noreferrer"&gt;To-Do List App Repo&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🔗 &lt;a href="https://github.com/hemanthbabu164/My-Projects/tree/master/VibeCoded-Projects/shopping-cart" rel="noopener noreferrer"&gt;Shopping Cart App Repo&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;💬 Also, the exact prompts used for Copilot are included inside the repo &lt;a href="https://github.com/hemanthbabu164/My-Projects/tree/master/VibeCoded-Projects" rel="noopener noreferrer"&gt;VibeCoded-Projects&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;




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

&lt;p&gt;I used to think hackathons were about caffeine, chaos, and typing fast.&lt;/p&gt;

&lt;p&gt;Now?&lt;/p&gt;

&lt;p&gt;It’s about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clear thinking&lt;/li&gt;
&lt;li&gt;Smart delegation&lt;/li&gt;
&lt;li&gt;And knowing which AI does what best&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This wasn’t "cheating."&lt;br&gt;&lt;br&gt;
It was leveraging the best tools available — and letting humans focus on orchestration.&lt;/p&gt;

&lt;p&gt;The future isn’t just developers typing faster — it’s &lt;strong&gt;developers thinking better&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 What’s Next?
&lt;/h2&gt;

&lt;p&gt;This is just one example. I’ve been using the same AI-assisted workflows for client projects too — like building &amp;amp; deploying websites in a single evening. (Wrote about that too.)&lt;/p&gt;

&lt;p&gt;There’s more coming — and more experiments to try.&lt;/p&gt;

&lt;p&gt;Until then… keep prompting. The future is listening.&lt;/p&gt;




</description>
      <category>webdev</category>
      <category>vibecoding</category>
      <category>hackathon</category>
      <category>githubcopilot</category>
    </item>
    <item>
      <title>⚡ How I Built and Deployed a Client’s Website in 90 Minutes — with AI as My Pair Programmer</title>
      <dc:creator>Hemanth Babu</dc:creator>
      <pubDate>Sun, 29 Jun 2025 10:07:19 +0000</pubDate>
      <link>https://dev.to/hemanthbabu164_76/how-i-built-and-deployed-a-clients-website-in-90-minutes-with-ai-as-my-pair-programmer-1a3c</link>
      <guid>https://dev.to/hemanthbabu164_76/how-i-built-and-deployed-a-clients-website-in-90-minutes-with-ai-as-my-pair-programmer-1a3c</guid>
      <description>&lt;h1&gt;
  
  
  ⚡ How I Built and Deployed a Client’s Website in 90 Minutes — with AI as My Pair Programmer
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🧑‍💼 Friend’s uncle needed a quick landing page for ABC Logistics&lt;/li&gt;
&lt;li&gt;🧠 Used ChatGPT for planning + Claude Sonnet (in Copilot) for rapid dev&lt;/li&gt;
&lt;li&gt;🛠️ Built the page, added branding &amp;amp; feedback-driven tweaks&lt;/li&gt;
&lt;li&gt;🌐 Deployed it for free using GitHub Pages + GoDaddy DNS&lt;/li&gt;
&lt;li&gt;⚡ Done in ~90 minutes — AI-assisted dev is a cheat code!&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;




&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The Setup&lt;/strong&gt;:&lt;br&gt;&lt;br&gt;
A friend asked me to build a website for his uncle’s new business.&lt;br&gt;
All I had was a PowerPoint, a domain name, and an open evening.&lt;br&gt;
So I teamed up with some smart AI agents — and we got it done in one sitting.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  📨 A Tiny Ask That Snowballed
&lt;/h2&gt;

&lt;p&gt;It started like most side gigs do — a casual message from a friend:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Hey, my uncle’s launching a company. He needs a simple landing page. Can you help?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There wasn’t much to go on. Just a &lt;code&gt;.pptx&lt;/code&gt; with some basic info, a logo file, and a domain name they’d already bought. No developer on their team. No fancy design specs. Just a blank slate and a simple ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“It should look professional… and we don’t want to spend on hosting.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Perfect.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Planning with ChatGPT: The Invisible PM
&lt;/h2&gt;

&lt;p&gt;Before touching any code, I fired up ChatGPT and shared everything I had — the context, constraints, and files.&lt;/p&gt;

&lt;p&gt;It became my project manager in seconds.&lt;/p&gt;

&lt;p&gt;We mapped out a high-level plan:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Extract structured content from the PowerPoint&lt;/li&gt;
&lt;li&gt;Design a lightweight, single-page layout&lt;/li&gt;
&lt;li&gt;Incorporate branding from the logo&lt;/li&gt;
&lt;li&gt;Host it somewhere free&lt;/li&gt;
&lt;li&gt;Connect it to the client’s domain&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What would’ve taken 30 minutes of thinking or scribbling got distilled into a clear action plan in 30 seconds.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧑‍💻 My AI Pair Programmer Goes to Work
&lt;/h2&gt;

&lt;p&gt;For implementation, I leaned on GitHub Copilot’s &lt;strong&gt;Chat (Agent Mode)&lt;/strong&gt; — which, under the hood, was using Claude Sonnet 4. That model is surprisingly good at front-end work.&lt;/p&gt;

&lt;p&gt;With a single prompt:&lt;/p&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;I want to build a simple, responsive landing page for a logistics company called ABC LOGISTICS. The page should be clean, professional, and mobile-friendly. Use only HTML, CSS, and optionally TailwindCSS or a lightweight framework—no backend logic is needed.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The structure should include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A header with the company name and tagline&lt;/li&gt;
&lt;li&gt;An "About Us" section&lt;/li&gt;
&lt;li&gt;A Services section (split into Logistics and Employee Transport Services)&lt;/li&gt;
&lt;li&gt;A Sustainability or Green Initiatives section&lt;/li&gt;
&lt;li&gt;A Contact section (with address, phone, and email)&lt;/li&gt;
&lt;li&gt;An optional Call-to-Action at the bottom&lt;/li&gt;
&lt;li&gt;A footer with minimal legal/disclaimer text&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's the {{Extracted content}} that should be used to fill in the sections.&lt;/p&gt;

&lt;p&gt;💡 The result should be a single HTML file (or include an external CSS file if needed) that I can easily host. Optimize for clarity and visual balance.&lt;/p&gt;


&lt;/blockquote&gt;

&lt;p&gt;Boom — HTML and CSS, styled and ready to go.&lt;/p&gt;

&lt;p&gt;I didn’t write a single line of layout code from scratch. Just reviewed, tweaked a few labels, and it looked clean on the first try.&lt;/p&gt;

&lt;p&gt;Adding the logo? Copilot handled that too.&lt;br&gt;&lt;br&gt;
Aligning elements, changing backgrounds, cleaning up sections? All handled via short follow-up prompts.&lt;/p&gt;

&lt;p&gt;The only thing I had to do manually was clean the background of the &lt;code&gt;.jpg&lt;/code&gt; logo using an online tool. Everything else — structure, styling, polish — came from prompting.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔄 The Feedback Loop
&lt;/h2&gt;

&lt;p&gt;As with any real-world project, a few edits came in later.&lt;/p&gt;

&lt;p&gt;My friend shared a couple of requests:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Remove some extra company details&lt;/li&gt;
&lt;li&gt;Make the layout more minimal&lt;/li&gt;
&lt;li&gt;Adjust mobile view for cleaner contact info&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I just passed these as prompts to Copilot.&lt;br&gt;&lt;br&gt;
It iterated like a good junior dev — fast, consistent, and tireless.&lt;/p&gt;




&lt;h2&gt;
  
  
  🌐 From Prompt to Production (Without Spending a Rupee)
&lt;/h2&gt;

&lt;p&gt;Once the page looked good, I set up a GitHub repository and used the platform’s free static site hosting. For connecting the domain, I had to do a bit of DNS wizardry — just following chatgpt's lead.&lt;/p&gt;

&lt;p&gt;Within 90 minutes of starting, the website was up and running on the client’s domain.&lt;/p&gt;

&lt;p&gt;No infrastructure. No deployment scripts.&lt;br&gt;&lt;br&gt;
Just AI-stitched web magic — no scripts, no stress.&lt;/p&gt;




&lt;h2&gt;
  
  
  📌 Why This Felt Different
&lt;/h2&gt;

&lt;p&gt;This wasn’t just a “build a page” story.&lt;/p&gt;

&lt;p&gt;It was a real taste of how development is evolving:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ChatGPT acted as strategist, spec-writer, and reviewer&lt;/li&gt;
&lt;li&gt;Copilot (Claude Sonnet under the hood) handled 90% of the implementation&lt;/li&gt;
&lt;li&gt;I became the &lt;strong&gt;orchestrator&lt;/strong&gt;, not the factory&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For once, I wasn’t chasing edge cases or fiddling with flexbox. I was just &lt;em&gt;telling&lt;/em&gt; the tools what I wanted — and they built it.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧭 The Bigger Picture
&lt;/h2&gt;

&lt;p&gt;We often talk about “AI replacing developers.” But the real power is in &lt;strong&gt;augmenting&lt;/strong&gt; us.&lt;/p&gt;

&lt;p&gt;This wasn’t about speed — though finishing it in 90 minutes felt good.&lt;/p&gt;

&lt;p&gt;It was about how seamless and &lt;em&gt;fun&lt;/em&gt; it felt:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No tutorial rabbit holes&lt;/li&gt;
&lt;li&gt;No blank-canvas paralysis&lt;/li&gt;
&lt;li&gt;Just clear ideas, fast execution, and space for creativity&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If anything, it left me more excited for the future of development.&lt;/p&gt;




&lt;h2&gt;
  
  
  💬 Curious About the Stack?
&lt;/h2&gt;

&lt;p&gt;If you're wondering what helped me pull this off:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ChatGPT (for planning, extraction, strategy)&lt;/li&gt;
&lt;li&gt;GitHub Copilot w/ Claude Sonnet 4 (for generation + feedback loops)&lt;/li&gt;
&lt;li&gt;GitHub Pages (for zero-cost hosting)&lt;/li&gt;
&lt;li&gt;A friend’s trust (for creative freedom)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧩 Final Thought
&lt;/h2&gt;

&lt;p&gt;We’re entering a time where a solo dev with AI tools can ship professional results — fast.&lt;/p&gt;

&lt;p&gt;This wasn’t a hackathon or startup sprint.&lt;br&gt;&lt;br&gt;
Just a quiet evening, a small ask, and the right tools.&lt;/p&gt;

&lt;p&gt;And sometimes, that’s all it takes.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔮 What’s Next?
&lt;/h2&gt;

&lt;p&gt;This isn’t the end of my AI-assisted dev adventures. I’ve even used similar workflows during a company hackathon (more on that soon 👀).&lt;/p&gt;

&lt;p&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%2Fg2jbda7sij9tkl6c858m.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%2Fg2jbda7sij9tkl6c858m.png" alt="Image description" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;




</description>
      <category>webdev</category>
      <category>vibecoding</category>
      <category>githubcopilot</category>
      <category>chatgpt</category>
    </item>
    <item>
      <title>The MongoDB Role Pitfalls That Bit Me: Lessons in Multi-Customer Access Control</title>
      <dc:creator>Hemanth Babu</dc:creator>
      <pubDate>Sat, 21 Jun 2025 13:56:16 +0000</pubDate>
      <link>https://dev.to/hemanthbabu164_76/the-mongodb-role-pitfalls-that-bit-me-lessons-in-multi-customer-access-control-4g2l</link>
      <guid>https://dev.to/hemanthbabu164_76/the-mongodb-role-pitfalls-that-bit-me-lessons-in-multi-customer-access-control-4g2l</guid>
      <description>&lt;h1&gt;
  
  
  The MongoDB Role Pitfalls That Bit Me: Lessons in Multi-Customer Access Control
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;❌ Global roles don't auto-scope to each customer databases&lt;/li&gt;
&lt;li&gt;🎯 Create roles per customer database&lt;/li&gt;
&lt;li&gt;🔐 Define privileges exactly where they apply&lt;/li&gt;
&lt;li&gt;🤖 Automate role/user creation for scale&lt;/li&gt;
&lt;li&gt;🔄 Always restart after config changes&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🔍 Intro: "I thought I understood MongoDB access control... until I didn't."
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;I'd just published a guide on setting up MongoDB users and custom roles. See the tutorial-style primer on &lt;a href="https://dev.to/hemanthbabu164_76/mongodb-access-control-creating-secure-users-with-custom-roles-48f5"&gt;Dev.to version&lt;/a&gt; or &lt;a href="https://medium.com/@hemanthbabu1121/mongodb-access-control-creating-secure-users-with-custom-roles-2916bf953658" rel="noopener noreferrer"&gt;Medium version&lt;/a&gt;. It covered the commands, the theory, and a neat walkthrough.&lt;/p&gt;

&lt;p&gt;Confidently, I thought: “Great—now I can lock down any MongoDB instance.” But when I tried to adapt that for a multi-customer, multi-module SaaS environment, things fell apart in unexpected ways.&lt;/p&gt;

&lt;p&gt;In this post, I'll share &lt;strong&gt;exactly&lt;/strong&gt; what I tried, &lt;strong&gt;why&lt;/strong&gt; it didn't work, and how I fixed it. If you're building a MongoDB setup where each customer has its own database and each module/service should only see its own collections, these lessons will save you headaches. And if you haven't read the tutorial-style primer yet, check it out here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dev.to: &lt;a href="https://dev.to/hemanthbabu164_76/MongoDB-access-control-creating-secure-users-with-custom-roles-48f5"&gt;https://dev.to/hemanthbabu164_76/mongodb-access-control-creating-secure-users-with-custom-roles-48f5&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Medium: &lt;a href="https://medium.com/@hemanthbabu1121/MongoDB-access-control-creating-secure-users-with-custom-roles-2916bf953658" rel="noopener noreferrer"&gt;https://medium.com/@hemanthbabu1121/MongoDB-access-control-creating-secure-users-with-custom-roles-2916bf953658&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🏗️ What I Was Trying to Build
&lt;/h2&gt;

&lt;p&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%2Ful68fnem06gtbzs0d0ky.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%2Ful68fnem06gtbzs0d0ky.png" alt="Diagram: What I Was Trying to Build" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Architecture in simple terms&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A SaaS-like application where &lt;strong&gt;each customer has its own database&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Within each customer database, multiple modules/services (e.g., orders, products, analytics) each have dedicated collections.&lt;/li&gt;
&lt;li&gt;Each module (i.e., the code/service) uses a MongoDB user to access only its own collections for that specific customer.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;strong&gt;End goal&lt;/strong&gt;: When Service A runs for Customer X, it connects with credentials that allow only the “CustomerX*ServiceA” collections. It must _never* access ServiceB collections or CustomerY data.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;strong&gt;Initial idea&lt;/strong&gt;: Create roles at the admin level—one role per module/service that spans all customer databases. Then, for each customer, assign that role scoped to the customer database. I assumed that specifying &lt;code&gt;{ role: "&amp;lt;moduleRole&amp;gt;", db: "&amp;lt;customerDb&amp;gt;" }&lt;/code&gt; in &lt;code&gt;db.createUser()&lt;/code&gt; would filter the module role's privileges to that customer database.&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;In short: I thought I could define one “ServiceA” role globally, then assign it with db= to restrict it to that DB. Spoiler: that assumption was wrong.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  ⚠️ The Misunderstanding: “db” in &lt;code&gt;createUser&lt;/code&gt; Is Where the Role Lives, Not Its Scope Filter
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Initial Plan (Wrong assumption)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Pseudocode for each module role created once under admin database:&lt;/span&gt;
&lt;span class="nx"&gt;use&lt;/span&gt; &lt;span class="nx"&gt;admin&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createRole&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;serviceA&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;privileges&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="c1"&gt;// Suppose we try to list resource patterns under many DBs:&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;resource&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;db&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;customer1_db&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;serviceA_*&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="na"&gt;actions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;find&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;insert&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;update&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;remove&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="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;resource&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;db&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;customer2_db&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;serviceA_*&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="na"&gt;actions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;find&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;insert&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;update&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;remove&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="c1"&gt;// ...and so on for each customer&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;roles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then for user creation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;use&lt;/span&gt; &lt;span class="nx"&gt;customerX_db&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createUser&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;customerX_serviceA_user&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;pwd&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;passwordPrompt&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="na"&gt;roles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;serviceA&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;db&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;customerX_db&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="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I assumed:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;“By specifying &lt;code&gt;db: "customerX_db"&lt;/code&gt;, the serviceA role's privileges get filtered to customerX_db only.”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Reality: Role's &lt;code&gt;db&lt;/code&gt; parameter is &lt;strong&gt;where&lt;/strong&gt; the role is defined, not a filter of where it applies.
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;{ role: "...", db: "customerX_db" }&lt;/code&gt; in &lt;code&gt;createUser&lt;/code&gt; means “look for a role named ‘serviceA' in the &lt;code&gt;customerX_db&lt;/code&gt; database.” It does &lt;em&gt;not&lt;/em&gt; say “apply the global serviceA role only in this DB.”&lt;/li&gt;
&lt;li&gt;If “serviceA” role was created under &lt;code&gt;admin&lt;/code&gt; (or any other DB), referencing it under &lt;code&gt;customerX_db&lt;/code&gt; fails (role not found), or if found under another DB, privileges don't magically filter to the user's connect-DB context.&lt;/li&gt;
&lt;li&gt;MongoDB's RBAC: A role's actions/resources are defined exactly where you create the role. Assigning that role to a user requires you refer to that same DB where the role exists.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Lesson&lt;/strong&gt;: You cannot “create once globally and assign with filtering by specifying db in createUser.” The &lt;code&gt;db&lt;/code&gt; is the namespace of the role definition.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🔄 How I Fixed It: Role Creation Per Customer Database
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Approach:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;For each customer database&lt;/strong&gt;, create distinct roles for each module/service.&lt;/li&gt;
&lt;li&gt;When creating the user for a module in that customer DB, reference the role in the same DB.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Example Flow (pseudo-automation script style):
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// For each customer (e.g., customerX_db):&lt;/span&gt;
&lt;span class="nx"&gt;use&lt;/span&gt; &lt;span class="nx"&gt;customerX_db&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// 1. Create or update role for ServiceA in this customer DB:&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;roleName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;serviceA&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// consider prefixing with module name or include customer in name if desired&lt;/span&gt;
&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createRole&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;roleName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;privileges&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;resource&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;db&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;customerX_db&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;serviceA_orders&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="na"&gt;actions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;find&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;insert&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;update&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;remove&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="c1"&gt;// Note: MongoDB privileges require exact collection names; wildcards aren't supported here, so list each collection explicitly.&lt;/span&gt;

  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;roles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// 2. Create user for ServiceA in this customer DB:&lt;/span&gt;
&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createUser&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;customerX_serviceA_user&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;pwd&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;passwordPrompt&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="na"&gt;roles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;roleName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;db&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;customerX_db&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="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;You repeat this for ServiceB, ServiceC, etc., in each customer DB.&lt;/li&gt;
&lt;li&gt;If you have many customers, script this process (e.g., a Node.js or Bash script that loops customer list).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Why This Works:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Role is defined in the same database where its privileges apply, so no confusion.&lt;/li&gt;
&lt;li&gt;When the service connects with &lt;code&gt;mongodb://customerX_serviceA_user:pwd@host:27017/customerX_db?authSource=customerX_db&lt;/code&gt;, it gets only the privileges defined in that DB's role.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Tip: If you have common privilege patterns per module, template the JSON structure and programmatically fill in the &lt;code&gt;db&lt;/code&gt; and &lt;code&gt;collection&lt;/code&gt; names per customer.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🔧 Bonus Pitfall: Enabling Authentication in mongod.cfg
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What happened&lt;/strong&gt;: After editing &lt;code&gt;mongod.cfg&lt;/code&gt; to add:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;  &lt;span class="c1"&gt;# In mongod.cfg, ensure 'security:' is at root indentation level; YAML is indentation-sensitive.&lt;/span&gt;

  &lt;span class="na"&gt;security&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;authorization&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;enabled&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I tried connecting with the new users, but MongoDB still allowed unauthenticated access.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Root cause&lt;/strong&gt;: Didn't restart the MongoDB service/process after config change.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Fix&lt;/strong&gt;: Always restart or reload the &lt;code&gt;mongod&lt;/code&gt; service after modifying the config file.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;On Windows, use Services UI or &lt;code&gt;net stop MongoDB&lt;/code&gt;, &lt;code&gt;net start MongoDB&lt;/code&gt; (or the equivalent PowerShell commands).&lt;/li&gt;
&lt;li&gt;On Linux, &lt;code&gt;sudo systemctl restart mongod&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;strong&gt;Lesson&lt;/strong&gt;: Authentication “not working” is often because the config change isn't live yet.&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;




&lt;h2&gt;
  
  
  📈 What I Learned (and You Should Know)
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Understand that the &lt;code&gt;db&lt;/code&gt; field specifies where roles live, not their access scope.&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;db&lt;/code&gt; field in &lt;code&gt;createRole&lt;/code&gt; and in user's &lt;code&gt;roles&lt;/code&gt; assignment refers to where the role is defined, not a dynamic filter. Always create roles in the DB where they should apply.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multi-customer (multi-DB) adds complexity&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;One-size-fits-all global roles often don't work. Better to script role/user creation per customer DB.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automate repetitive setup&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;If you have tens or hundreds of customers, manually creating roles/users is error-prone. Build scripts or use Infrastructure-as-Code.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test early and often&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Spin up a staging customer database, create roles/users, verify permissions before rolling out widely.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Restart after config changes&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Simple but easily overlooked; always confirm &lt;code&gt;authorization: enabled&lt;/code&gt; is in effect.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  ✅ Conclusion &amp;amp; Next Steps
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Key takeaway&lt;/strong&gt;: Don't assume MongoDB will scope a global role by specifying a different &lt;code&gt;db&lt;/code&gt; at user-creation time. Define roles in the exact database where their privileges apply. (For the basic tutorial on custom roles, see &lt;a href="https://dev.to/hemanthbabu164_76/mongodb-access-control-creating-secure-users-with-custom-roles-48f5"&gt;My previous MongoDB ACL tutorial on Dev.to&lt;/a&gt;.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Call to action&lt;/strong&gt;: Have you tackled MongoDB RBAC in a multi-DB environment? What strategies or scripts did you use? Share your approaches or questions in the comments below!&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>mongodb</category>
      <category>security</category>
      <category>acl</category>
      <category>database</category>
    </item>
    <item>
      <title>MongoDB Access Control: Creating Secure Users with Custom Roles</title>
      <dc:creator>Hemanth Babu</dc:creator>
      <pubDate>Mon, 16 Jun 2025 17:42:26 +0000</pubDate>
      <link>https://dev.to/hemanthbabu164_76/mongodb-access-control-creating-secure-users-with-custom-roles-48f5</link>
      <guid>https://dev.to/hemanthbabu164_76/mongodb-access-control-creating-secure-users-with-custom-roles-48f5</guid>
      <description>&lt;h1&gt;
  
  
  🔐 MongoDB Access Control: Creating Secure Users with Custom Roles
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ Create an admin user with full privileges&lt;/li&gt;
&lt;li&gt;🧱 Define custom roles for specific collections&lt;/li&gt;
&lt;li&gt;👥 Assign roles to users per database&lt;/li&gt;
&lt;li&gt;🔒 Enable access control in MongoDB config&lt;/li&gt;
&lt;li&gt;🔗 Use correct connection strings with &lt;code&gt;authSource&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🚀 Why MongoDB Access Control Matters
&lt;/h2&gt;

&lt;p&gt;Security isn't optional—especially when you're dealing with databases that store critical application data. MongoDB, one of the most popular NoSQL databases, offers powerful access control mechanisms that let you define &lt;em&gt;who&lt;/em&gt; can do &lt;em&gt;what&lt;/em&gt;—right down to the collection level.&lt;/p&gt;

&lt;p&gt;In this guide, you'll learn how to set up user-based authentication and &lt;strong&gt;custom roles&lt;/strong&gt; to secure your MongoDB deployment like a pro. Whether you're managing dev environments or preparing for production, this setup will help you sleep better at night.&lt;/p&gt;




&lt;h2&gt;
  
  
  🛠️ Step-by-Step: Setting Up Access Control in MongoDB
&lt;/h2&gt;

&lt;h3&gt;
  
  
  🔑 1. Create the Admin User
&lt;/h3&gt;

&lt;p&gt;Let’s begin with setting up an admin user who has the power to manage users and roles across all databases.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;use&lt;/span&gt; &lt;span class="nx"&gt;admin&lt;/span&gt;

&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createUser&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;myUserAdmin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;pwd&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;passwordPrompt&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="na"&gt;roles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;userAdminAnyDatabase&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;db&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&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="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;readWriteAnyDatabase&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;db&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&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="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💡 &lt;em&gt;The &lt;code&gt;userAdminAnyDatabase&lt;/code&gt; role allows this user to create, modify, and assign roles across all databases.&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🧱 2. Define a Custom Role (Fine-Grained Access Control)
&lt;/h3&gt;

&lt;p&gt;Want to allow users access only to specific collections like &lt;code&gt;products&lt;/code&gt; and &lt;code&gt;orders&lt;/code&gt;? Create a &lt;strong&gt;user-defined role&lt;/strong&gt; tailored to those needs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;use&lt;/span&gt; &lt;span class="nx"&gt;mydb&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createRole&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;editor&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;privileges&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;resource&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;db&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mydb&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;products&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="na"&gt;actions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;find&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;insert&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;update&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;remove&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="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;resource&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;db&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mydb&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;orders&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="na"&gt;actions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;find&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;insert&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;update&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;remove&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="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;roles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="c1"&gt;// Inherited roles (leave empty if none)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🧠 &lt;em&gt;Think of this like giving someone keys to just two rooms in a building—not the whole building.&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  👤 3. Assign the Role to a User
&lt;/h3&gt;

&lt;h4&gt;
  
  
  ✅ Option A: Create the User (if they don’t exist yet)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;use&lt;/span&gt; &lt;span class="nx"&gt;mydb&lt;/span&gt;

&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createUser&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;myUser&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;pwd&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;passwordPrompt&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="na"&gt;roles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;editor&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;db&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mydb&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="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;read&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;db&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;reporting&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="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  🔄 Option B: Update an Existing User
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;use&lt;/span&gt; &lt;span class="nx"&gt;mydb&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;updateUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;myUser&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="na"&gt;roles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;editor&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;db&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mydb&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="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔐 &lt;em&gt;Roles are assigned per database, so always specify both the role and the target DB.&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🧪 4. Verify Users and Roles
&lt;/h3&gt;

&lt;p&gt;Before moving forward, it’s good practice to check that everything is set up correctly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;use&lt;/span&gt; &lt;span class="nx"&gt;admin&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUsers&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getRoles&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use this to confirm that the users and their assigned roles appear as expected.&lt;/p&gt;




&lt;h3&gt;
  
  
  ⚙️ 5. Enable Access Control in MongoDB Config
&lt;/h3&gt;

&lt;p&gt;This step locks the door and turns on the bouncer. Modify your MongoDB configuration file:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Path:&lt;/strong&gt; &lt;code&gt;C:\\Program Files\\MongoDB\\Server\\8.0\\bin\\mongod.cfg&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Security section&lt;/span&gt;
&lt;span class="na"&gt;security&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;authorization&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;enabled&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;📁 &lt;em&gt;After saving the file, restart your MongoDB service for changes to take effect.&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🔗 6. Connect with Authenticated Access
&lt;/h3&gt;

&lt;p&gt;Here’s how your MongoDB URI looks when connecting with credentials:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mongodb://myUser:myPassword@localhost:27017/mydb?authSource=mydb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✨ &lt;em&gt;Notice the &lt;code&gt;authSource=mydb&lt;/code&gt;? That’s telling MongoDB where to verify credentials.&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 Conclusion: Lock It Down Like a Pro
&lt;/h2&gt;

&lt;p&gt;By now, you’ve:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Created an admin user&lt;/li&gt;
&lt;li&gt;Defined custom roles&lt;/li&gt;
&lt;li&gt;Assigned those roles to users&lt;/li&gt;
&lt;li&gt;Enabled authentication&lt;/li&gt;
&lt;li&gt;Verified and connected securely&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This setup gives you tight control over who can access what in your database. Whether you're building a multi-user app or just locking down a staging server, these best practices put security front and center.&lt;/p&gt;




&lt;h2&gt;
  
  
  💬 What’s Next?
&lt;/h2&gt;

&lt;p&gt;What other MongoDB topics would you like to see covered? Maybe role inheritance, replica set authentication, or integration with external identity providers? Let’s continue the conversation—drop your thoughts in the comments below!&lt;/p&gt;

</description>
      <category>mongodb</category>
      <category>security</category>
      <category>database</category>
      <category>backend</category>
    </item>
  </channel>
</rss>
