By creating indexes in a MongoDB collection, query performance is enhanced because they store the information in such a manner that traversing it becomes easier and efficient. There is no need for a full scan as MongoDB can search the query through indexes. Thus it restricts the number of documents that need to be checked for query criteria.
Syntax– create_index([str1, direction], [str1, direction]……., optional)
- str : string used for naming index, it can be one or more than one
- direction : can be one or many directions, it has to be one of these directions- descending, ascending, hashed, geosphere, geohaystack, geo2d or text
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Indexing Multi-dimensional arrays in Python using NumPy
- Basic Slicing and Advanced Indexing in NumPy Python
- Python | Add the element in the list with help of indexing
- Python | Indexing a sublist
- Indexing and Selecting Data with Pandas
- Boolean Indexing in Pandas
- Slicing, Indexing, Manipulating and Cleaning Pandas Dataframe
- Label-based indexing to the Pandas DataFrame
- Create a database in MongoDB using Python
- 3D Plotting sample Data from MongoDB Atlas Using Python
- How to fetch data from MongoDB using Python?
- How to access a collection in MongoDB using Python?
- Drop Collection if already exists in MongoDB using Python
- How to create index for MongoDB Collection using Python?
- Count the number of Documents in MongoDB using Python
- Aggregation in MongoDB using Python
- How to import JSON File in MongoDB using Python?
- Web Scraping CryptoCurrency price and storing it in MongoDB using Python
- Connect Django Project to MongoDB using Django
- MongoDB and Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.