Loading lessons...
Get Started with MongoDB
Get Started with MongoDB
MongoDB can be installed locally on your own hardware, or hosted in the cloud. For most beginners the cloud option - MongoDB Atlas - is much easier.
Local vs Cloud
- Local: download the open source Community Server and manage your own server, upgrades, and maintenance.
- Cloud (Atlas): MongoDB manages the infrastructure for you. Free tiers make it easy to start.
Create an Atlas cluster
- Sign up for a free MongoDB Atlas account.
- Create a free Shared Cluster and choose a cloud provider and region.
- Atlas is locked down by default, so:
- Under Database Access, create a database user and note the username and password.
- Under Network Access, add your IP address to the allow list.
Install mongosh
mongosh is the MongoDB Shell. Verify it's installed by opening a terminal:
mongosh --version
You should see the installed version number.
Connect to the database
In Atlas, click Connect on your cluster, choose "Connect with the MongoDB Shell", and copy the connection string. It looks like this:
mongosh "mongodb+srv://cluster0.ex4ht.mongodb.net/myFirstDatabase" --apiVersion 1 --username YOUR_USER_NAME
Paste it into your terminal and press enter. You'll be prompted for your database user password - and then you're connected!
What's next
Once connected, you can use mongosh to create, read, update, and delete (CRUD) data - and later use MongoDB from backend technologies like Node.js.
TL;DR
- MongoDB runs locally (Community Server) or in the cloud (Atlas).
- Atlas: create a free cluster, add a database user, allow your IP.
- Install mongosh, copy the connection string, and connect.