Prerequisites: MongoDB and Python
With the help of drop_indexes() method we can drop all the indexes in a Collection. No parameter is passed in the method. Only default index _id can not be deleted. All the Non _id indexes will be the drop by this method. It means we can only drop the index which we have created.
Sample database used:
By default, each collection has the _id index. All collections compulsorily have at least one index. If all indexes are removed, then a new index will be automatically generated. We can see the indexes present by running the following command:
Now, we can run the following code to add a new Index called newIndex to the collection, given that the mongo server is running:
Example 1: Adding an Index to the Collection
Example 2: Deleting the Index from the Collection
- How to rebuild all the indexes of a collection using PyMongo?
- Get all the information of a Collection's indexes using PyMongo
- Get all the Documents of the Collection using PyMongo
- Update all Documents in a Collection using PyMongo
- Drop Collection if already exists in MongoDB using Python
- MongoDB python | Delete Data and Drop Collection
- What is a PyMongo Cursor?
- Get the Names of all Collections using PyMongo
- Nested Queries in PyMongo
- Convert PyMongo Cursor to JSON
- How to check if the PyMongo Cursor is Empty?
- Convert PyMongo Cursor to Dataframe
- Difference Between insert(), insertOne(), and insertMany() in Pymongo
- Python | Accessing all elements at given list of indexes
- Python | Change column names and row indexes in Pandas DataFrame
- Using Timedelta and Period to create DateTime based indexes in Pandas
- How to Create a Pivot table with multiple indexes from an excel sheet using Pandas in Python?
- Python | Pandas Index.drop()
- Python | Pandas Series.drop()
- Python - Channel Drop using Pillow
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.