createIndex

noun

say it: “kree-AYT IN-deks” /kriˈeɪt ˈɪndɛks/

A MongoDB method that builds an index on one or more fields of a collection.

What does createIndex do?

createIndex builds an index on the fields you name, 1 for ascending or -1 for descending, and answers with the index's name. Running it again with the same fields changes nothing.

db.orders.createIndex({ customerId: 1 });
// customerId_1

In a sentence

  • “One createIndex on customerId took the order lookup from two seconds to two milliseconds.”
  • “createIndex answered customerId_1, the name of the new index.”

Level: Journeyman · More MongoDB terms at this level

Updated