MongoDB Atlas Indexing Strategies for Enterprise Business OS
# Boosting Database Performance
In database-driven applications like a CRM or ERP system, query latency directly impacts user experience. When loading pages, sorting leads, or filtering client invoices, we must optimize how Prisma interacts with MongoDB Atlas.
1. Single and Compound Indexes
By default, querying fields like `email` or `clientId` causes a full collection scan if indexes aren't configured.
In Prisma, you can define indexes directly in your `schema.prisma` model block:
```prisma model Lead { id String @id @default(auto()) @map("_id") @db.ObjectId email String status String @@index([email]) @@index([status, email]) } ```
Compound indexes are vital when executing filter grids in the CRM Kanban view.
2. Managing Soft Deletes
In enterprise systems, we rarely delete records permanently. Instead, we use soft-deletes via a `deletedAt` timestamp field. To ensure that checking `deletedAt == null` doesn't degrade performance, ensure this field is indexed alongside active query parameters.
