db.users.createIndex({ email: 1 })Ideal for identity or lookup fields.
Single-field, compound, multikey, text, wildcard, partial, TTL, and unique index patterns for MongoDB.
Match index type to the document shape and query shape.
db.users.createIndex({ email: 1 })Ideal for identity or lookup fields.
db.orders.createIndex({ tenantId: 1, status: 1, createdAt: -1 })Column order still matters in MongoDB compound indexes.
Index documents that contain array values.
db.products.createIndex({ tags: 1 })MongoDB automatically creates a multikey index when the indexed field contains arrays.
db.orders.createIndex(
{ createdAt: -1 },
{ partialFilterExpression: { shippedAt: { $exists: false } } }
)A strong way to shrink index size for hot subsets such as unshipped orders.
db.sessions.createIndex({ expiresAt: 1 }, { expireAfterSeconds: 0 })Useful for sessions, caches, temporary tokens, and ephemeral telemetry.
db.events.createIndex({ "$**": 1 })Wildcard indexes can help when documents contain highly variable keys, though they should be used carefully.
Measure whether an index reduced keys and docs examined.
Inspect planner and runtime behavior.
db.orders.find({ tenantId: 7, status: "paid" }).sort({ createdAt: -1 }).explain("executionStats")Check keys examined, docs examined, winning plan, and whether the compound index is actually used.