DEV Community

Surya ganthan
Surya ganthan

Posted on

MongoDB Basics

Here are the steps to download MongoDB compass

  1. Open your preferred Browser.
  2. Open https://www.mongodb.com/products/tools/compass

  1. Click on download now.

CREATING A CLUSTER ON MongoDB Atlas

  1. Visit https://www.mongodb.com/products/platform/atlas-database
  2. Create your free account.
  3. Create a new Organization and a New Project.
  4. Go to Clusters
  5. Click on Create new Cluster
  6. Use free tier.
  7. Click on OK.

![ ](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wdbllq88xk4hcnlg

Creating a sample database

  1. In clusters , go to browse collections.
  2. Click on Create database.
  3. Now click on insert document.
  4. Add your details inside the edit option

  1. Now you can see your given details are added to the database.

Steps to get the connection string

  1. Head to the cluster.
  2. Click the Overview option.
  3. Click on CONNECT option.
  4. Add current IP address [ In the network configuration ].
  5. Click on MongoDB compass and you will see the connection string

Steps to connect with MongoDB compass

  1. After you got the connection string , open MongoDB compass.
  2. Click on ' Add New Connection ' option.
  3. Paste the String you got.
  4. Change the password [ what you gave while creating database ].
  5. Now click on ' Save and Connect '.

CRUD operations in MongoDB compass

  1. Open shell after connecting to the db.
  2. Switch to your database and select/create your desired collection.

----- EVERY COMMAND SHOWN IS AN EXAMPLE -----

Inserting values

--> use command - db..insertOne({"val1":"val2"})

Updating values

--> use command - db..updateOne(
{ new_val1: "new_val2" },
{ $set: { "profile.age": 25, "profile.city": "Chennai" } }
)

Deleting values

--> use command - db.First.deleteOne({ val1: "val2" })

@shabhika_s_7a4d920629082b @santhoshnc @aravind_66ac0038974374783

Top comments (0)