How to create an Index on MongoDB on ubuntu 20.04 LTS - TechBeginner

Welcome to TechBeginner.in, Tech Beginner provides technical blog for Online Linux Tutorials, Ubuntu Tutorials, Redhat Tutorials and CentOS 7, Configuration of server like Web Server, Application server, Database server, Window server, networking, html, css, java script, php, wordpress, opencart, magento, joomla and etc.

How to create an Index on MongoDB on ubuntu 20.04 LTS

Share This


 

MongoDB Indexes are most important things in any database, and with MongoDB it's the same. With the utilization of Indexes, performing questions in MongoDB turns out to be more productive.

In the event that you had an assortment with a large number of archives with no files, and afterward you inquiry to discover certain records, at that point in such case MongoDB would have to filter the whole assortment to discover the reports. In any case, in the event that you had files, MongoDB would utilize these records to restrict the quantity of reports that must be looked in the assortment.

Indexes are unique informational indexes which store a halfway piece of the assortment's information. Since the information is fractional, it gets simpler to peruse this information. This halfway set stores the worth of a particular field or a bunch of fields requested by the worth of the field.

 

Making an Index in MongoDB is finished by utilizing the "createIndex" strategy.

The accompanying model shows how add list to assortment. How about we expect to be that

we have our equivalent Employee assortment which has the Field names of

"User_name_id" and "UserName".

 

To create mongoDB indexes DB Admin need to collect the repeated queries 

 

Step 1: Login MongoDB Shell

 

Login the mongoDB using Shell by using the following commands. 

mongo 

 

Step 2 : Choose Database

 

Use your database to create indexes by following the commands. use 

database_name 

 

Step 3: Choose Collection

 

After did that admin need to check status of the collection by following the commands. 

show collections 

 

Step 4 : Creating Index

 

To create indexes you need to choose any collection name and prepared with indexes data, use the following commands to create index using collection. 

db.collection_name_here.createIndex({index_name_here:1}) 



Step 5: Find Indexes: getindexes()

 

Finding an Index in MongoDB is done by using the "getIndexes" method. The following example shows how this can be done

db.collection_name.getIndexes()

 

Step 6: Drop Indexes: dropindex()

 

Removing an Index in MongoDB is done by using the dropIndex method. The following example shows how this can be done

db.collection_name.dropIndex(index_name_here:1)

 


Conclusion

 
We have successfully create MongoDB index on ubuntu linux, Still you have any issue leave a comment.


No comments:

Post a Comment