Complete Developer Course
A comprehensive guide to MongoDB — from your first document to building production-ready REST APIs with Mongoose and JWT authentication. 8 lessons covering everything a modern developer needs.
| Command | Description |
|---|---|
show dbs | List all databases |
use mydb | Switch to database |
show collections | List collections |
db.col.insertOne({}) | Insert one document |
db.col.find({}).sort().limit() | Query with cursor methods |
db.col.updateOne({}, {$set:{}}) | Update first match |
db.col.deleteMany({}) | Delete all matches |
db.col.aggregate([]) | Run aggregation pipeline |
db.col.createIndex({field:1}) | Create an index |
db.col.find({}).explain("executionStats") | Analyze query performance |
| Operator | Use |
|---|---|
$set | Set a field value |
$unset | Remove a field |
$inc | Increment a number |
$push | Add to array |
$pull | Remove from array |
$addToSet | Add to array (no duplicates) |
$rename | Rename a field |
$currentDate | Set to current date |
| Stage | SQL Equivalent | Purpose |
|---|---|---|
$match | WHERE | Filter documents |
$group | GROUP BY | Group & aggregate |
$project | SELECT | Shape output fields |
$sort | ORDER BY | Sort documents |
$limit | LIMIT | Cap output count |
$lookup | JOIN | Join collections |
$unwind | flatten | Expand arrays |
$facet | multi-query | Multiple pipelines at once |