Sikau

MongoDB · Day 1 · about 20 min

What is MongoDB?

Documents and collections instead of rows and tables.

Data shaped like your objects

MongoDB stores documents — JSON-like objects with nested fields and arrays — in collections. A dish with its tags and ingredients is one document, just like the object in your JavaScript code. No schema is required up front, which makes it popular for fast-moving products.

insertOne and find

db.dishes.insertOne({
  name: "Momo",
  price: 180,
  tags: ["popular", "steamed"],
  stock: { qty: 20, unit: "plates" },
});

db.dishes.insertOne({ name: "Masala tea", price: 50, hot: true });

printjson(db.dishes.find().toArray());
print("dishes:", db.dishes.countDocuments());
  • SQL vs MongoDB: table ↔ collection, row ↔ document, column ↔ field, JOIN ↔ embedding or $lookup.
  • On your computer: MongoDB Atlas (free cloud cluster) or a local install, and the mongosh shell.

The rest of this lesson

  • Documents, BSON and _idexplain
  • When MongoDB fitsexplain
  • What's _id?predict
  • SQL word, MongoDB wordmatch
  • Your turnwrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 15 lessons of MongoDB