MongoDB Atlas
Atlas is MongoDB's hosted cloud service, so you get a database without installing or managing servers.
In this page:
Syntax
mongodb+srv://username:[email protected]/database_name
mongosh "connection_string"
MongoDB Atlas
Create a free cluster on cloud.mongodb.com, add a database user, allow your IP address in Network Access, and copy the connection string. The mongodb+srv scheme finds the cluster through DNS. Atlas handles backups, scaling and upgrades.
Note:
The free M0 tier is enough for learning and small projects.
Example: MongoDB Atlas
$ mongosh "mongodb+srv://cluster0.abcde.mongodb.net/shop" --username appUser
Enter password: ********
Atlas atlas-abc123-shard-0 [primary] shop>
// In Node.js, keep the string in an environment variable
const uri = process.env.MONGODB_URI; // mongodb+srv://appUser:<password>@cluster0.abcde.mongodb.net/shop
⚠️ Run this in your own terminal or Node.js environment.
Related Topics
Common Mistakes
- Forgetting to allow your IP address
- Committing the connection string with the password
- Using the wrong database user
Chapter Summary
- Atlas is hosted MongoDB
- Create a cluster and a database user
- Allow your IP in network access
- Connect with a mongodb+srv string
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: