A single field index is the most common index type. It creates a B-Tree on one field of a document (top-level or nested). Direction (1 ascending, -1 descending) is functionally irrelevant for single field indexes — MongoDB traverses the B-Tree in either direction equally.
// Ascending index on email (direction irrelevant for single field) db.users.createIndex({ email: 1 }, { name: "idx_email" }) // Index on a nested embedded field db.users.createIndex({ "address.city": 1 }, { name: "idx_city" }) // Unique email constraint db.users.createIndex({ email: 1 }, { unique: true, name: "idx_email_unique" })
What Single Field Indexes Provide
- Equality —
{ email: "x@y.com" }→ IXSCAN - Range —
{ age: { $gte: 18, $lt: 65 } }→ IXSCAN - Sort elimination — if sorting by the indexed field, no in-memory sort needed
- Covered queries — combined with projection limiting output to indexed fields
_id for every collection. It is unique, ascending, and cannot be dropped or modified.