Create Indexing in MongoDB via Terminal

Vineet Mishra
Jan 14, 2022

--

Introduction: Indexing are used to swiftly locate data without having to search every row in a database table every time a database table is accessed

Note: I will you to recommend using indexing before putting the data into your database

Let's start with opening the terminal:

go to your MongoDB (where you installed the MongoDB Compass)bin folder and copy the folder path up to the bin and paste in terminal

Run the command:

mongo

Now run these commands one by one

  1. show “dbs” that will show databases that are present in your MongoDB

2. now select the database by command “use <database_name>”

3. now run this to create an index in the collection

index db.<collection_name>.createIndex(<indexVariable>:<indexVariableValue>)

Thank you😎!!!!!

--

--

Vineet Mishra
Vineet Mishra

Written by Vineet Mishra

SDE 2 at Accelya , I write about Mobile/Web Development and Deployment, and Interview Q & A

No responses yet