Crud Operations in MongoDB Compass Commands with Examples


Hi friends, in this tutorial, you will learn how to perform crud operations in MongoDB compass commands with examples. So, to perform the create, read, update, and delete operations, you must know about SQL, MongoDB the difference between SQL and MongoDB, and why MongoDB, etc. Let us start a brief discussion as given below.

Also read, How to Use express JS Middleware for All Routes

SLDescription
1What is SQL
2Establish the connection to the MongoDB database
3What is MongoDB
4Why MongoDB
5Establish the connection to the MongoDB database
6Display existing databases in MongoDB using compass commands
7Display all the collections of a database using compass commands
8Inserting / Creating data in the collections using compass commands
9Viewing the inserted data of a collection using compass commands
10Updating data of a collection using compass commands
11Deleting data of a collection using compass commands
What is SQL:-
  • SQL is a structured query language by which we can perform various operations such as inserting data in the table of a database, fetching the data from a table in the database, updating data in the table of a database, and deleting data from a particular table using conditions.
  • SQL stores data in the form of rows and columns in the table.

What is Mongodb:-

MongoDB is a tool and known as document type database which stores table data in the form of collections.
Collections holds the data values or field values in the form of objects almost like json data.

Why MongoDB:-

  • Mongodb is faster than SQL and it allows us to enter the additional fields automatically as much as we can without manual intervention.
  • But in the case of SQL, we have to create additional fields manually if needed.

Establish the connection to the MongoDB database

  • First of all download and install the MongoDB compass tool.
  • Now, open the compass tool and click on connect to make a new connection to MongoDB. It will connect the preconfigured databases.
crud operations in MongoDB compass

Display existing databases in MongoDB using compass commands

  • Now, click on MONGOSH shown at the bottom of the compass tool and it will open the command terminal.
  • Now you can run the below command to display all the existing databases.

Creating databases and collections in the MongoDB compass tool

  • To create the databases in MongoDB compass tool, you can click on the Create Database button as shown below.
crud operations in MongoDB compass
  • To create collections in the compass tool, click on Create Collection button as shown below
  • Now, you can enter the collection name as shown below.
crud operations in MongoDB compass

Display all the collections of a database using compass commands

Now, to display all the collections of a particular database, you can run db.getCollectionNames() as shown below.

Inserting / Creating data in the collections using compass commands and tool

In this case, we can insert data in two ways.

  • By manually inserting data in the tool by choosing the ADD DATA option as shown in the below image.
crud operations in MongoDB compass

Now, add the data in the collection objects and click on insert button as shown below

crud operations in MongoDB compass
  • Now, we can also insert data using the terminal using the db.collectionName.insertOne(). This method will insert only a single row data at a time as shown below

Put the data inside the curly braces {} separated by when using the insertOne() function.

Viewing the inserted data of a collection using compass commands

Now, if you want to view the inserted data then you can do so with the help of db.collection.find() as shown below.

Updating data of a collection using compass commands

Now, it is time to update or modify the inserted data. In order to do so, you can use the db.collection.updateOne() method as shown in the below image

Put two curly braces {} seperated by : when using updateOne() function. The first curly brace includes the conditional field by which the data should be updated and the second curly brace will include the $set variable which holds the new data to be replaced.

After executing the above command, you can again check the data using db.collection.find() and you will see that the data has been updated as given below.

crud operations in MongoDB compass

Deleting data of a collection using compass commands

  • In this case, you can delete data manually using the compass tool but I will show you how to delete the inserted data using the compass command line as given in the below image
  • Now, after executing the above delete command based on the condition, the data has been successfully deleted from the collection array and you will see the updated collection as given in the below image.

Also read, How to use forEach loop in Node JS template engine

Conclusion:- I hope this tutorial will help you to understand the concept of crud operations in MongoDB. If there is any doubt then please leave a command below.


Leave a Comment

KUPU178

Live Casino Roullate

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

KUPU178

KUPU178

THOR311

THOR311

THOR311

RATU311

CERI188

DAFTAR KUPU178

LINK DAFTAR CERI188

CERI188

sabung ayam online

APK KUPU178

KUPU178

CERI188

CERI188

RATU311

KUPU178

THOR311 DOMINO QQ

judi bola online

Mix Parlay

CERI188

CERI188

CERI188

KUPU178

RATU311

live casino online

RATU311

Mix Parlay

Sabung Ayam Online

Slot PG Soft

CERI188

RATU311

RATU311

RATU311

RATU311

CERI188

THOR311

CERI188

THOR311

RATU311

THOR311

Game Thor311

THOR311

HOKI311

live casino

sv388

HOKI311

HOKI311

slot mahjong

Thor311 Alternatif

RATU311

HOKI311

HOKI311

HOKI311

HOKI311

CERI188

THOR311 RESMI

THOR311 AKSES

THOR311

THOR311 RTP

RATU311

RATU311

THOR311

parlay

HOKI311

RATU311

THOR311

Ceri188

Thor311 Game Online

Thor311 Aplikasi

LINK CERI188

RATU311 NONTON BOLA

RATU311

CERI188 Link RTP LIVE

THOR311

Thor311 Live Casino

CERI188

akses VIP THOR311

THOR311

link daftar THOR311

THOR311

situs thor311

THOR311 LOGIN

THOR311

THOR311

RATU311

RATU311

HOKI311 Link SABUNG AYAM RESMI

HOKI311 Link QRIS EWALLET

RATU311

LINK CERI188

parlay

HOKI311 Link RTP Gacor

THOR311

RATU311

THOR311

HOKI311 Link Apk Resmi

KUPU178

RATU311

RATU311

CERI188

CERI188 Situs Spaceman Terbaik 2026

KUPU178 Link Daftar

CERI188

CERI188

CERI188

CERI188

CERI188

HOKI311

THOR311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

CERI188 Live Casino

HOKI311 Lapak Arena Slot

RATU311 judi bola

CERI188 Live Casino

HOKI311 Link Spaceman Online

HOKI311 Link Daftar Resmi

CERI188 Toto SGP Online

KUPU178

KUPU178

KUPU178

KUPU178

HOKI311 TEMBAK IKAN ONLINE

RATU311

CERI188 PANDUAN MAXWIN SLOT ONLINE

RATU311

RATU311

KUPU178

HOKI311 Link Login Alternatif

HOKI311 Live Casino Online

HOKI311 Situs Slot Gacor

THOR311

THOR311

situs judi bola

Ceri188 Game Online

CERI188

link login CERI188

link login CERI188

CERI188

link login CERI188

link login CERI188

link daftar CERI188

THOR311

HOKI311

HOKI311

CERI188

CERI188

CERI188

parlay

THOR311

RATU311

RATU311

HOKI311

HOKI311

parlay

HOKI311

RATU311

THOR311

KUPU178

HOKI311

KUPU178

KUPU178

KUPU178

HOKI311

parlay

slot gacor

kupu178 link alternatif

kupu178 slot

kupu178 daftar

kupu178 login

link daftar kupu178

judi bola

HOKI311

RATU311

link alternatif RATU311

Link daftar RATU311

link login RATU311

RATU311

RATU311

RATU311

RATU311

KUPU178

KUPU178

THOR311

KUPU178

KUPU178

KUPU178

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

THOR311

RATU311

KUPU178

KUPU178

HOKI311

THOR311

KUPU178

THOR311

THOR311

slot thailand

judi bola

THOR311

THOR311

KUPU178

THOR311

situs bola

THOR311

slot gacor

slot gacor

yakuza303

slot gacor

unobet77

slot gacor

slot gacor

RATU311

parlay

parlay

slot gacor

mix parlay

judi bola

judi bola

mix parlay

parlay

judi bola

sv388

judi bola

judi bola

judi bola

parlay

THOR311