MONGODB Tutorial



MongoDB BASICS


📚 MongoDB Basics

MongoDB is a NoSQL database that stores data in flexible, JSON-like documents. Let's look at some of the core concepts you need to know to get started.

🔹 Basic Terminology

  • Database: A container for collections.
  • Collection: A group of MongoDB documents (like a table in SQL).
  • Document: A record in MongoDB, stored in BSON format (similar to JSON).

📌 Sample Document

{
  "_id": "101",
  "name": "John Doe",
  "email": "john@example.com",
  "age": 25,
  "skills": ["JavaScript", "MongoDB", "Node.js"]
}
  

Each document can have different fields — MongoDB is schema-less.

💻 Common MongoDB Shell Commands

  • show dbs – List all databases
  • use mydb – Switch to or create a new database named "mydb"
  • show collections – List all collections in the current database

📥 Insert a Document

db.users.insertOne({
  name: "Alice",
  age: 28,
  email: "alice@example.com"
});
  

🔍 Find Documents

db.users.find();              // Show all documents
db.users.findOne();           // Show first document
db.users.find({ age: 28 });   // Filter by field
  

📝 Update a Document

db.users.updateOne(
  { name: "Alice" },
  { $set: { age: 29 } }
);
  

❌ Delete a Document

db.users.deleteOne({ name: "Alice" });
  
✅ Tip: MongoDB is case-sensitive and uses JavaScript-style syntax in the shell.

🌟 Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review