⬅ Previous Topic
MongoDB with Node.js using MongooseNext Topic ⮕
Creating and Managing Databases in Atlas⬅ Previous Topic
MongoDB with Node.js using MongooseNext Topic ⮕
Creating and Managing Databases in AtlasMongoDB Atlas is the official cloud database service for MongoDB. It offers a free tier cluster that you can use to learn and develop applications without setting up MongoDB on your local system.
With Atlas, your database is hosted in the cloud, and you can connect to it from anywhere using a connection string.
Go to mongodb.com/cloud/atlas and sign up for a free account. You can use your email or sign in with Google or GitHub.
Question: Why use MongoDB Atlas instead of installing MongoDB locally?
Answer: Atlas lets you skip installation and manage your database from any machine. It also offers cloud backups, monitoring, and easy scaling—all for free in the basic tier.
MyFirstProject
.M0
.Cluster0
).It may take 1–3 minutes to deploy your free cluster.
mongoUser
, mongoPass123
).0.0.0.0/0
).Note: You can restrict this later for better security.
Node.js
(or any language)mongodb+srv://...
).Example MongoDB connection string:
mongodb+srv://mongoUser:mongoPass123@cluster0.asdf.mongodb.net/test?retryWrites=true&w=majority
Question: What is the retryWrites=true&w=majority
part?
Answer: It's an option to enable retrying writes automatically and writing to the majority of nodes for consistency in the cluster.
You can also connect using the command-line shell:
mongo "mongodb+srv://cluster0.asdf.mongodb.net/test" --username mongoUser
Enter password: ******** MongoDB shell version v5.x.x connecting to: mongodb+srv://cluster0.asdf.mongodb.net/test >
Now you're connected to your remote Atlas cluster using the Mongo shell!
use testDatabase
db.students.insertOne({
name: "Arjun",
course: "MongoDB Basics",
enrolled: true
});
{ acknowledged: true, insertedId: ObjectId("...") }
This document is now saved in the cloud, in your MongoDB Atlas database.
This setup is ideal for working on MongoDB projects from anywhere, without worrying about local configuration or server uptime.
Let’s now explore how to connect your MongoDB Atlas database to code — using Node.js or Python to perform CRUD operations!
⬅ Previous Topic
MongoDB with Node.js using MongooseNext Topic ⮕
Creating and Managing Databases in AtlasYou can support this website with a contribution of your choice.
When making a contribution, mention your name, and programguru.org in the message. Your name shall be displayed in the sponsors list.