Prisma ORM: A Complete Guide for Node.js Developers
Schema design, migrations, relations, transactions and performance tips for using Prisma with PostgreSQL, MySQL or MongoDB.
A query that takes 5 ms with 1,000 documents can take seconds with a million. Indexes are the difference.
Without an index, MongoDB scans every document in the collection. An index is a sorted structure that lets it jump straight to matches, the way a book index points to pages.
If you often filter posts by status and sort by date:
db.posts.createIndex({ status: 1, publishedAt: -1 });
In Prisma, declare it in the schema with @@index([status, publishedAt]).
Order the fields as Equality, then Sort, then Range. An index on { status, publishedAt } serves "status equals published, newest first" perfectly.
db.posts.find({ status: 'PUBLISHED' }).sort({ publishedAt: -1 }).explain('executionStats');
Look for IXSCAN (good) rather than COLLSCAN (a full scan), and compare totalDocsExamined with the number returned.
Return only the fields you use. Large text fields on list queries waste memory and bandwidth.
In MongoDB, a missing field and an explicit null are different. A filter like deletedAt: null matches documents where the field is null or missing, but ORMs may translate it differently, and range operators on null can behave unexpectedly. Always test soft-delete and cleanup queries on a copy of your data before running them in production.
Every index slows writes and uses memory. Add indexes for real queries and remove unused ones.
Index for your actual queries, order compound indexes by Equality, Sort, Range, and verify with explain.
Schema design, migrations, relations, transactions and performance tips for using Prisma with PostgreSQL, MySQL or MongoDB.
A fair comparison of document and relational databases: data modelling, consistency, scaling and the questions that decide the right choice.
Stop guessing. Measure first, then apply the React optimizations that move the needle: memoization, code splitting, list rendering and more.