Thuta Learning
MongoDB
AdvancedData & DatabasesIntermediate

Indexes

MongoDBLesson 15

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)

Updated on

Progress is saved only in this browser on this device. It isn't synced to other devices.

Report a problem with this lessonOpens your email app with this lesson's address filled in — nothing is sent until you send it.

Indexes | Thuta Learning