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

RATU311

RATU311

RATU311

KUPU178

THOR311

THOR311

THOR311

THOR311

KUPU178

RATU311

RATU311

RATU311

slot online

kupu178

thor311

thor311

kupu178

kupu178

RATU311

RATU311

KUPU178

THOR311

THOR311

THOR311

KUPU178

slot mahjong ways

hoki311

slot gacor

ceri188

ratu311

kupu178

Casino Baccarat Online

kupu178

kupu178

ceri188

ceri188

THOR311

RATU311

KUPU178

THOR311

RATU311

toto macau

KUPU178

slot gacor

HOKI311

sabung ayam online

RATU311

SLOT LUCKY NEKO

CERI188

Slot Gacor

KUPU178

RATU311

KUPU178

RATU311

Link Spaceman

CERI188

Slot Gacor Online

THOR311

Mahjong ways

KUPU178

THOR311

THOR311

Live Casino

HOKI311

CERI188

CERI188

KUPU178

THOR311

THOR311

THOR311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

THOR311

KUPU178

KUPU178

CERI188

HOKI311 SLOT

TOTO TOGEL TOKYO

CERI188

CERI188 SITE

CERI188

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

KUPU178

THOR311

Toto Togel

KUPU178

Slot Mahjong

CERI188

ARENA SABUNG AYAM

RATU311

CERI188

CERI188

Slot Sweet Bonanza 2500

KUPU178

SLOT ONLINE

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

KUPU178

KUPU178 X SLOT777

CERI188

sabung ayam online

THOR311

judi bola online

THOR311

KUPU178 10 GAME SLOT TERBAIK

KUPU178

KUPU178 SLOT TERPERCAYA

KUPU178 TOGEL

TOTO 4D MACAU

KUPU178

TOGEL ONLINE

KUPU178

SITUS BOLA

CERI188

KUPU178

THOR311

RATU311

CERI188

THOR311

THOR311

CERI188

HOKI311

CERI188

KUPU178

KUPU178

KUPU178

KUPU178

RATU311

THOR311

CERI188

Slot Mahjong Ways

KUPU178

CERI188

Slot Online Resmi

KUPU178

KUPU178

RATU311 SLOT ONLINE

KUPU178

KUPU178 TOTO MACAU

KUPU178: Link Akses Resmi

KUPU178: Strategi Menang Di Game Live Casino

KUPU178

KUPU178: Minimal 200 Rupiah

Slot Gacor Online

KUPU178

Mix Parlay

CERI188

CERI188

THOR311

THOR311

THOR311

THOR311

THOR311

KUPU178

CERI188

Slot Gacor Online

KUPU178

Slot Thailand

CERI188

CERI188

THOR311 RTP

RATU311

RATU311

RATU311

Mahjong Ways 2

CERI188

CERI188

CERI188

KUPU178 TOTO SLOT

CERI188 TOTO Singapore

THOR311

KUPU178

KUPU178

KUPU178

RATU311

CERI188

CERI188

RATU311: Alternatif karnpuracollege

RATU311

RATU311

Thor311 Terbaru

THOR311 MAHJONG

RATU311: BONUS SABUNG AYAM

CERI188

CERI188

CERI188: Masuk Akun Slot Super Cepat

THOR311 PRO

THOR311

CERI188

CERI188

CERI188

CERI188

CERI188

CERI188

CERI188

CERI188

THOR311

HOKI311

HOKI311

RATU311

KUPU178

HOKI311

KUPU178

RATU311

THOR311 TOTO4D

RATU311

RATU311

RATU311

RATU311

THOR311

CERI188

DAFTAR KUPU178

LINK DAFTAR CERI188

CERI188

CERI188

CERI188

RATU311

KUPU178

THOR311 DOMINO QQ

judi bola online

Mix Parlay

CERI188

CERI188

live casino online

RATU311

Mix Parlay

Slot PG Soft

CERI188

RATU311

RATU311

CERI188

THOR311

CERI188

THOR311

Game Thor311

HOKI311

HOKI311

Thor311 Alternatif

RATU311

HOKI311

THOR311 RESMI

THOR311 AKSES

HOKI311

THOR311

RATU311 NONTON BOLA

THOR311

Thor311 Live Casino

CERI188

akses VIP THOR311

THOR311

link daftar THOR311

THOR311

situs thor311

RATU311

HOKI311 Link QRIS EWALLET

RATU311

HOKI311 Link RTP Gacor

HOKI311 Link Apk Resmi

CERI188

KUPU178 Link Daftar

CERI188

CERI188

CERI188

CERI188

CERI188

HOKI311

RATU311 judi bola

KUPU178

HOKI311 Live Casino Online

situs judi bola

CERI188

link login CERI188

link login CERI188

CERI188

HOKI311

CERI188

THOR311

HOKI311

HOKI311

HOKI311

RATU311

THOR311

KUPU178

HOKI311

KUPU178

KUPU178

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

KUPU178

KUPU178

KUPU178

RATU311

RATU311

THOR311

KUPU178

KUPU178

HOKI311

THOR311

KUPU178

THOR311

THOR311

slot thailand

judi bola

THOR311

KUPU178

THOR311

THOR311

slot gacor

slot gacor

yakuza303

slot gacor

RATU311

THOR311