Thuta Learning
AdvancedData & Databasesintermediate

Indexes

Relax. We'll talk through this in plain words — no textbook voice.

Indexes are special data structures that boost MongoDB's query performance. Without an index, MongoDB has to scan the entire collection (a collection scan). With an index, a query can use the index to find data much faster.

javascript
// Create a single field index on the 'item' field
db.inventory.createIndex( { item: 1 } )

// 1 for ascending order, -1 for descending order
You should see
(This builds an index on the item field, so searches on that field will be faster)
Indexes | Thuta Learning