Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Prisma · Const

@@map

@@map maps a Prisma model to a differently named database table or MongoDB collection. It lets Prisma Client use a clean model name while preserving the database object's existing name.

How it works

Add @@map to a model to decouple its Prisma name from the underlying database object. Prisma Client uses the model name, while relational databases use the mapped table name and MongoDB uses the mapped collection name.

Syntax

@@map("tableOrCollectionName")
@@map(name: "tableOrCollectionName")

Parameters

NameTypeDescription
nameStringDatabase table name for relational databases, or collection name for MongoDB; the page also allows an underlying enum name.

Returns

No runtime value; this schema attribute controls the database object name used by Prisma ORM.

Key points

  • @@map connects a Prisma model to a differently named relational table or MongoDB collection.
  • The same attribute can map an enum name to a different database enum.
  • The required mapped value identifies the database table or collection that Prisma should use.
  • The name label is optional, so named and positional syntax are equivalent.

Common mistakes

  • Without @@map, Prisma expects the model name to match the relational table or MongoDB collection name.
  • Both named and positional forms are valid, so @@map(name: "users") and @@map("users") mean the same thing.

Example: Map a model to an existing table

model Comment {
  id Int @id @default(autoincrement())
  text String
  @@map("comments")
}

This keeps the Prisma model name Comment while reading and writing the existing comments table.

When to use it

Preserve database naming

A database table is named comments, but the schema should use the singular Comment model.

Work with legacy schemas

An existing database uses names that do not follow Prisma model naming conventions.

Separate API and storage names

The Prisma Client API should use domain-friendly model names without changing stored database object names.

Interview questions

QWhat does @@map do?

@@map maps a Prisma model name to a different database table or MongoDB collection name. This lets Prisma Client expose a model such as Comment while the database object is named comments.

Follow-up: How would you map a field as well? Use field-level @map, for example text String @map("comment_text"); @@map applies to the model, whereas @map applies to a field or enum value.

QWhat argument does @@map take?

Its required name value is the database table name for relational databases or collection name for MongoDB. The attribute can use either @@map("users") or @@map(name: "users").

Follow-up: What happens if the attribute is omitted? Prisma uses the model name itself as the table or collection name.

QWhy use @@map?

Use @@map when the database uses naming conventions or legacy names that differ from the names preferred in the Prisma schema. Prisma Client then remains idiomatic without requiring the underlying database object to be renamed.

Follow-up: Can @@map rename an enum in the database? Yes; the schema reference also documents mapping an enum name to a different underlying database enum.

  • @map
  • @@schema
  • prisma db pull

Source: Prisma Schema API (Prisma ORM v6). Checked 2026-10-16.