If I understand your question correctly, the request body may optionally contain an id or be undefined. If the id is present in the request, you want to update the corresponding record. If it isn't, you want to create a new record.

upsert functionality requires a unique identifier that can be used by the database to check whether there is a matching record. The database will then decide what to do. However with an undefined value, prisma cannot work.

You could use a key that will not exist in the database in case the value of id is undefined to make upsert insert the record in this case.

await prisma.profile.upsert({
  where: { id: id || '' },
  // ...
});

Or you could differentiate the cases and treat them appropriately:

if (id) {
  await prisma.profile.update({
    where: { id },
    data: {
      username,
      about,
      // ...
    },
  });
} else {
  await prisma.profile.create({
    data: {
      username,
      about,
      // ...
    },
  });
}

You might want to think about the case that there is an id given in the body, but it does exist in the database. Do you want the update to fail and reply with an error? Or do you want the database to silently insert? Then use upsert instead of update above.

Answer from some-user on Stack Overflow
🌐
Prisma
prisma.io › home › crud › crud › crud › crud
CRUD (Reference) | Prisma Documentation
const upsertUser = await prisma.user.upsert({ where: { email: "viola@prisma.io" }, update: { name: "Viola the Magnificent" }, create: { email: "viola@prisma.io", name: "Viola the Magnificent" }, });
🌐
Prisma Client Python
prisma-client-py.readthedocs.io › en › stable › reference › operations
Query Operations - Prisma Client Python - Read the Docs
In lieu of more extensive documentation, this page documents query operations on the prisma client such as creating, finding, updating and deleting records.
🌐
Goprisma
goprisma.org › docs › walkthrough › upsert
Upsert records – Prisma Client Go
October 22, 2024 - post, err := client.Post.UpsertOne( // query db.Post.ID.Equals("upsert"), ).Create( // set these fields if document doesn't exist already db.Post.Published.Set(true), db.Post.Title.Set("title"), db.Post.ID.Set("upsert"), ).Update( // update these fields if document already exists db.Post.Title.Set("new-title"), db.Post.Views.Increment(1), ).Exec(ctx)
🌐
Prisma
prisma.io › home › prisma client api › prisma client api › prisma client api
Prisma Client API | Prisma Documentation
When Prisma Client does an upsert, it first checks whether that record already exists in the database. To make this check, Prisma Client performs a read operation with the where clause from the upsert operation.
🌐
GitHub
github.com › prisma › prisma › discussions › 17974
Upsert into SQL table by multiple conditions failure in prisma python? #702 · prisma/prisma · Discussion #17974
My written code: record = db.table.upsert( where={'column1': 1, 'column2': 2, 'column3': 3} data={ 'create': { .... }, 'update': { .... }, }, ) And the error that I encounterd : prisma.errors.FieldNotFoundError: Failed to validate the query: `Expected exactly one field to be present, got 3.
Author   prisma
Find elsewhere
🌐
DEV Community
dev.to › dailydevtips1 › how-to-perform-non-updating-upserts-in-prisma-4e3a
How to perform non updating upserts in Prisma - DEV Community
October 28, 2021 - const playlist = await prisma.playlist.upsert({ where: { uri: uri, }, update: {}, create: playlistItem, });
🌐
Daily Dev Tips
daily-dev-tips.com › posts › how-to-perform-non-updating-upserts-in-prisma
Non-updating Upserts in Prisma [2024]
February 5, 2024 - You can use the upsert command to perform an upsert query in Prisma.
🌐
Medium
medium.com › @rsharma7_be22 › how-i-optimized-bulk-inserts-by-replacing-upsert-with-createmany-in-prisma-676fa74fb479
How I Optimized Bulk Inserts by Replacing .upsert with createMany in Prisma | by rohanS | Medium
July 30, 2025 - Initially, I was iterating over an array of founders and running an upsert for each one: await Promise.all( founders.map((founder) => prisma.userFounderStatus.upsert({ where: { userId_founderId: { userId: user.id, founderId: founder.id, }, }, update: {}, create: { userId: user.id, founderId: founder.id, isSent: false, }, }) ) );
🌐
Prisma
prisma.io › home › relation queries › relation queries › relation queries › relation queries
Relation queries (Concepts) | Prisma Documentation
const result = await prisma.post.update({ where: { id: 6, }, data: { author: { upsert: { create: { email: "bob@prisma.io", name: "Bob the New User", }, update: { email: "bob@prisma.io", name: "Bob the existing user", }, }, }, }, include: { author: true, }, });
🌐
YouTube
youtube.com › watch
Prisma Tutorial for Beginners #6 - CRUD - Updating Records - YouTube
Connect with me on LinkedIn: https://www.linkedin.com/in/khurram-ali1 ☕ Buy Me A Coffee ➜ https://www.buymeacoffee.com/giraffereactor Github Repo:https://gi...
Published   February 28, 2025