Document database foundations
Choose local MongoDB or Atlas
Run a disposable local database or create an Atlas deployment without exposing an unauthenticated server.
9 minute lesson
You have two sensible ways to get a MongoDB server: run MongoDB Community Edition locally, or create a deployment on MongoDB Atlas, the managed cloud service.
A local server is perfect for learning and isolated development. It costs nothing, starts instantly, and you can throw it away. On macOS, install it from the official Homebrew tap:
brew tap mongodb/brew
brew install mongodb-community
brew services start mongodb-community
Verify it is running before you continue:
brew services list | grep mongodb
# mongodb-community started flavio ~/Library/LaunchAgents/...
By default a local mongod binds to localhost only. Keep it that way. An unauthenticated MongoDB exposed to a network is one of the classic ways databases end up scraped and ransomed. If you ever change the bind address, configure authentication first and follow the official security checklist.
When Atlas is the better choice
Atlas gives you a managed deployment with authentication, network access rules, backups, and monitoring already wired up. The free M0 tier is enough for this course. Use Atlas when the application needs a shared environment your teammates or deployed services can reach, or when you want replica-set features without operating servers yourself.
Atlas connection strings use the mongodb+srv:// scheme and include credentials:
mongodb+srv://app_user:[email protected]/animals
Two Atlas defaults matter. First, nothing can connect until you add your IP to the IP Access List — a connection that hangs and then fails with a server-selection timeout is almost always this. Second, you create database users in the Atlas UI; use a dedicated application user with access to one database, not the admin account you registered with.
Record the boundary
Whichever you choose, create one practice database and write down four things before adding data: the connection endpoint, the user you connect as, the networks allowed to reach it, and the cleanup step that deletes it. That habit sounds bureaucratic for a lab. It is exactly the discipline that prevents a “temporary” open database in production.
Lesson completed