Database Tutorial #9: MongoDB Setup and CRUD
MongoDB stores data as documents — JSON-like objects with flexible structure. No fixed schema. No joins required for embedded data. This tutorial gets you up and running with MongoDB 8.0. Setup with Docker docker run -d \ --name mongodb \ -p 27017:27017 \ -e MONGO_INITDB_ROOT_USERNAME=admin \ -e MONGO_INITDB_ROOT_PASSWORD=password \ mongodb/mongodb-community-server:8.0-ubi8 Connect with mongosh: mongosh "mongodb://admin:password@localhost:27017" mongosh Basics // Show databases show dbs // Switch to (or create) a database use myapp // Show collections show collections // Create a collection explicitly (optional — auto-created on first insert) db.createCollection("users") Documents and Collections In MongoDB: ...