Indexes

Basic Index Operations

Create Index

// Single field index
db.users.createIndex({ email: 1 })

// Compound index
db.users.createIndex({ firstName: 1, lastName: 1 })

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

// Sparse index
db.users.createIndex({ phone: 1 }, { sparse: true })

// Text index
db.users.createIndex({ name: "text", description: "text" })

// Geospatial index
db.users.createIndex({ location: "2dsphere" })

// TTL index
db.sessions.createIndex({ createdAt: 1 }, { expireAfterSeconds: 3600 })

List Indexes

Drop Index

Index Types

Single Field Index

Compound Index

Unique Index

Sparse Index

Text Index

Geospatial Index

TTL Index

Partial Index

Wildcard Index

Index Options

Basic Options

Advanced Options

Index Management

Check Index Usage

Analyze Index Performance

Index Maintenance

Index Optimization

Query Optimization

Index Design Patterns

Equality, Sort, Range (ESR)

Compound Index Order

Index for Aggregation

Common Index Patterns

User Management

E-commerce

Order Management

Analytics

Index Best Practices

Performance Tips

Index Limitations

Index Sizing

Troubleshooting Indexes

Common Issues

Performance Issues

Last updated