MongoDB - Getting StartedMongoDB - Getting Started1

Setting Up a Free MongoDB Atlas Cluster



Setting Up a Free MongoDB Atlas Cluster

MongoDB 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.

Step 1: Create a MongoDB Atlas Account

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.

Step 2: Create a New Project

Step 3: Build a Cluster

It may take 1–3 minutes to deploy your free cluster.

Step 4: Create a Database User

Step 5: Whitelist Your IP Address

Note: You can restrict this later for better security.

Step 6: Connect to Your Cluster

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.

Step 7: Connect with Mongo Shell

You can also connect using the command-line shell:


    mongo "mongodb+srv://cluster0.asdf.mongodb.net/test" --username mongoUser
    

Output:

    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!

Step 8: Insert a Sample Document


    use testDatabase
    db.students.insertOne({
      name: "Arjun",
      course: "MongoDB Basics",
      enrolled: true
    });
    

Output:

    {
      acknowledged: true,
      insertedId: ObjectId("...")
    }
    

This document is now saved in the cloud, in your MongoDB Atlas database.

Summary

This setup is ideal for working on MongoDB projects from anywhere, without worrying about local configuration or server uptime.

Next Step

Let’s now explore how to connect your MongoDB Atlas database to code — using Node.js or Python to perform CRUD operations!



Welcome to ProgramGuru

Sign up to start your journey with us

Support ProgramGuru.org

Mention your name, and programguru.org in the message. Your name shall be displayed in the sponsers list.

PayPal

UPI

PhonePe QR

MALLIKARJUNA M