Back to Blog
2025-06-14Abyan Dimas

MongoDB Crash Course for SQL Developers

MongoDB

In SQL, you normalize data into separate tables. In MongoDB, you embed data.

Embedding vs Referencing

SQL (Reference): Users table and Addresses table. Join them when querying.

MongoDB (Embed):

{
  "_id": 1,
  "name": "Abyan",
  "address": {
    "street": "123 Main St",
    "city": "Jakarta"
  }
}

Store data together that is accessed together. This makes reads incredibly fast (no joins needed).

The Aggregation Pipeline

Mongo's powerful alternative to complex SQL queries.

db.orders.aggregate([
  { $match: { status: "A" } },
  { $group: { _id: "$cust_id", total: { $sum: "$amount" } } }
])

It's like a Unix pipe for your data. Filter -> Group -> Sort -> Project.

Share this article

Read Next