MongoDB Installation and Ways to Practice

You can learn MongoDB using a local installation, a managed cloud deployment, or a containerized environment. The right option depends on whether you want to focus on queries, local development, or deployment operations.

Option 1: MongoDB Atlas

MongoDB Atlas is MongoDB's managed database service. It provides hosted deployments and management features so you can practice without administering a database server yourself.

Create a deployment, configure an appropriate database user, allow the required network access, and obtain a connection string. Follow the current official instructions for your chosen environment.

Security note: avoid allowing unrestricted network access for production deployments. Use appropriate network restrictions, least-privilege database users, and secure secret storage.

Option 2: Local MongoDB installation

A local installation is useful for learning mongosh, creating databases and collections, running queries, and inspecting database behavior without depending on a remote service.

Install a MongoDB Community Server version supported by your operating system, and install or use a compatible MongoDB Shell (mongosh). Start the server and connect with the shell.

mongosh "mongodb://127.0.0.1:27017"

This command assumes a local MongoDB server is running on the default port and does not require authentication. If your local setup uses authentication or a different port, adjust the connection command accordingly.

Option 3: Docker

Docker can provide a repeatable development environment. The following command starts a local MongoDB container with a named persistent volume and credentials for local development:

docker volume create mongodb-course-data

docker run -d \
  --name mongodb-course \
  -p 127.0.0.1:27017:27017 \
  -e MONGO_INITDB_ROOT_USERNAME=courseadmin \
  -e MONGO_INITDB_ROOT_PASSWORD=local-dev-password-change-me \
  -v mongodb-course-data:/data/db \
  mongo:8.0

The command binds MongoDB to the local loopback interface rather than exposing it on every network interface. The example password is for a disposable local learning environment only; use a unique secret if adapting the command, and never use the example credentials in production.

The official image initializes the root user when it creates a fresh database directory. Changing the environment variables later does not automatically rotate an existing user's password.

Connect to this container with:

mongosh "mongodb://courseadmin:local-dev-password-change-me@127.0.0.1:27017/admin?authSource=admin"

Which option should you choose?

For a beginner, MongoDB Atlas is convenient if you prefer not to manage the server, while a local installation or Docker is useful for hands-on control. You can follow the course with any supported environment that provides mongosh and a MongoDB server.

Practice environments
MongoDB Atlas: Managed cloud deployment
Useful when you want a hosted database without maintaining the database server yourself.
Community Server: Local database installation
Useful for local development and learning server administration.
Docker: Containerized development
Useful for repeatable environments and isolated local experiments.
mongosh: MongoDB command-line shell
Useful for executing queries, inspecting collections, and practicing database commands.
Prepare one environment and reuse it

Use one working MongoDB environment for the course exercises. Keep a separate practice database, and avoid experimenting with destructive commands against production data.

Key Takeaways
  • MongoDB Atlas provides a managed deployment.
  • Local MongoDB installations provide direct control over the server.
  • Docker can provide a repeatable development environment.
  • mongosh is the interactive shell used in this course.
  • Use least-privilege access and secure credentials outside disposable local environments.
Knowledge Check

Which tool is designed to provide an interactive command-line shell for MongoDB?