π What is MongoDB? MongoDB is a NoSQL document-based database that stores data in JSON-like format. Instead of rows and columns, it uses collections and documents . This makes it super flexible and schema-less — perfect for fast-moving modern apps π. π‘ Difference vs SQL Databases: SQL = Tables, Rows, Columns π MongoDB = Collections, Documents π ❓Why Indexes Matter Imagine searching a phonebook without alphabetical order — painful, right? π
Indexes make your searches faster by letting MongoDB skip scanning every document. ⚡ Tip: Without indexes, MongoDB performs a collection scan — meaning it checks every record. That’s fine for 10 docs... not for 10 million! π§ Types of Indexes in MongoDB 1️⃣ Single Field Index Most basic and common. You index one field. db.users.createIndex({ "name": 1 }) 1 = ascending , -1 = descending . Used for queries like { name: "Priya" } . 2️⃣ Compound Index Multiple fields combined to improve multi-fi...
A cozy space where I share my daily Java learnings, issues, and solutions.