

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is to be done when MongoDB takes too much time to find the record?
To reduce the time to find record in MongoDB, you can use index. Following is the syntax −
db.yourCollectionName.createIndex({yourFieldName:1});
You can follow the below approaches to create index for field names based on number, text, hash, etc.
First Approach
Let us create an index. Following is the query −
> db.takeLessTimeToSearchDemo.createIndex({"EmployeeName":1}); { "createdCollectionAutomatically" : true, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 }
Second Approach
To understand the above concept, let us create another index −
> db.takeLessTimeToSearchDemo1.createIndex({"EmployeeName":"text"}); { "createdCollectionAutomatically" : true, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 }
Third Approach
Let us now create another index −
> db.takeLessTimeToSearchDemo2.createIndex({"EmployeeName":"hashed"}); { "createdCollectionAutomatically" : true, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 }
- Related Questions & Answers
- Why is MongoDB taking too much time to find the record?
- Connecting SAP B1 via DI API takes too much time
- What is to be done when text overflows the containing element with JavaScript?
- Why do I sweat too much, Is it bad for me?
- What can be done to control water pollution?
- Is it necessary to select the database each time we begin a MySQL session? How can it be done?
- How to find a record by _id in MongoDB?
- Program to Find Out the Number of Corrections to be Done to Fix an Equation in Python
- Python program to find how much money will be earned by selling shoes
- Bootstrap Event when the modal is about to be shown
- Bootstrap Event when the modal is about to be hidden
- Why is India a poor country and what needs to be done to make it rich once again?
- MongoDB query to find a specific city record from a collection
- Find when the keys are unknown in MongoDB?
- How do you find a MongoDB record that is two level deep?
Advertisements