Problem Statement
What is the default index automatically created by MongoDB for every collection?
Explanation
MongoDB automatically creates a unique index on the underscore id field for every collection. This index ensures that each document has a unique identifier and enables fast lookups by underscore id.
You cannot drop this index because it is essential for MongoDB's internal operations. The underscore id index is a single-field index that uses a B-tree data structure for efficient searching. All other indexes must be created manually based on your query patterns.
Code Solution
SolutionRead Only
// View indexes on a collection
db.users.getIndexes()
// Returns:
[
{
"v": 2,
"key": { "_id": 1 },
"name": "_id_"
}
]