Index Prefix

noun

say it: “IN-deks PREE-fiks” /ˈɪndɛks ˈprifɪks/

The first field, or first few fields, of an index on several fields, which a query can use on its own.

What is an index prefix?

An index prefix is the first field, or first few fields, of a compound index. An index on { customerId: 1, placedAt: -1 } also serves queries on customerId alone, but not queries on placedAt alone.

db.orders.createIndex({ customerId: 1, placedAt: -1 });
db.orders.find({ customerId: 31 });                             // uses it: customerId is its prefix
db.orders.find({ placedAt: { $gte: ISODate("2026-01-01") } });  // can't use it

In a sentence

  • “Because customerId is the index prefix, the same index serves 'all of Ana's orders'.”
  • “A query on placedAt alone isn't on any index prefix, so it scans the collection.”

Level: Freelancer · More MongoDB terms at this level

Updated