Setting Up MongoDB Atlas and Performing CRUD Operations Using MongoDB Compass
Creating an Account on dev.to
I initially created an account on dev.to and logged in.
Installing MongoDB Compass on Linux
Next, I installed the latest version of MongoDB Compass for Linux as a .deb
file via the terminal using the following commands:
wget https://downloads.mongodb.com/compass/mongodb-compass_1.43.3_amd64.deb
sudo apt install ./mongodb-compass_1.43.3_amd64.deb -y
Registering on MongoDB Atlas
After that, I created an account on MongoDB Atlas and signed in.
Creating a MongoDB Atlas Cluster
I created a free cluster on MongoDB Atlas.
After creating the cluster, I loaded the sample dataset.
Browsing Collections and Database Creation
I clicked "Browse Collections."
Then, I clicked Create Database and set the Database Name as 24SY040 and Collection Name as 24SY040.
Inserting Initial Document
After creating the database successfully, I inserted the following document:
id:24SY040
"Name": "Prasanth"
Creating a Database User
Next, I created a new user named temp_user with read and write permissions.
Configuring Network Access
Next, I went to the Network Access tab and added a new IP address by selecting the "Access from anywhere" option.
Connecting via MongoDB Compass
Then, I clicked the Connect option, selected Compass, and clicked Done.
Next, from MongoDB Compass, I pasted the connection URL with my username and password, then clicked Connect.
Performing CRUD Operations
In the MongoDB Compass, I spawned a shell and put the command "use 24SY040"
Create operation
db["24SY040"].insertOne({ name: "Aravind", roll_no: "24SY004" })
Read operation
db["24SY040"].find().pretty()
Update operation
db["24SY040"].updateOne(
{ name: "Aravind" },
{ $set: { roll_no: "24SY040" }}
)
Delete operation
db["24SY040"].deleteOne({ name: "Aravind" })
Thank you!
@santhoshnc
Top comments (0)