MongoDB 8 · Indexes and performance

Create a unique index

Reject documents with a duplicate value.

db.users.createIndex({ email: 1 }, { unique: true })

Official MongoDB 8 documentation

More indexes and performance commands

All indexes and performance commands · MongoDB 8 cheatsheet

Was this page helpful?