Hide sensitive fields
A User model contains passwords or other secrets that should not appear in ordinary query results.
Prisma · Pipe
Prisma Client's omit option excludes selected model fields from returned results. It can be applied globally on the client or locally to one query, making it useful for hiding sensitive fields such as passwords.
omit removes named fields from Prisma Client result objects. Configure it when constructing the client for a model-wide default, or place it in one query to affect only that operation; this is useful when most fields are wanted but a few should be hidden.
omit: { fieldName: true }| Name | Type | Description |
|---|---|---|
omit | XOR<UserOmit, null> | Object whose field names map to boolean values indicating which result fields to exclude; at client scope it is grouped by model. |
A Prisma Client result object without the fields marked for omission.
omit when the usual result is appropriate except for a small set of fields.import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient({
omit: {
user: { password: true },
},
})
async function main() {
const user = await prisma.user.findUnique({ where: { id: 1 } })
console.log(user) // password is excluded
}
main().finally(() => prisma.$disconnect())Creates a Prisma Client that excludes the password field from every User query.
A User model contains passwords or other secrets that should not appear in ordinary query results.
Most model properties are needed, but a few internal or noisy properties should be removed from a response.
An individual endpoint needs a narrower result without changing the client's default behavior.
omit solve, and when should it be used instead of select?omit specifies fields that Prisma Client excludes from returned objects. It is the better choice when the normal model result is mostly needed and only a small number of fields should be removed.
Follow-up: When would select be preferable? Use select when only a small subset of fields is needed rather than when most fields should remain.
Put omit in the Prisma Client constructor with a model-to-fields map. That exclusion applies to queries made through that client instance.
Follow-up: How can one query re-include a globally omitted field? Supply an overriding query option or use a specific select, as documented.
Add omit to an individual query and set each field to true. The exclusion then applies only to that query.
Follow-up: How do you omit several fields? Add multiple field-and-true entries to the same omit object.
selectPrismaClientfindUniquefindManyUserOmit