question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prisma Client upsert returns count instead of data

See original GitHub issue

Bug description

When using the upsert method to do a findOrCreate implementation, count: { 1 } is returned rather than the data itself.

How to reproduce

Using the following code returns count rather than the user object

const user = await prisma.user.upsert({
  where: { email: emails[0].value },
  update: { lastLoggedIn: new Date() },
  create: {
    email: emails[0].value,
    name: displayName,
    avi: photos[0].value,
    profile: {
      create: {
        name: displayName,
        avi: photos[0].value,
        email: emails[0].value,
      },
    },
  },
});

console.log({ user });

Expected behavior

I expect the user’s data to be returned.

Prisma information

model User {
  id           String   @id @default(uuid())
  email        String   @unique
  name         String
  avi          String?
  createdAt    DateTime @default(now())
  updatedAt    DateTime @updatedAt
  lastLoggedIn DateTime @default(now())

  log           Log[]
  items         Item[]
  rsvps         Rsvp[]   @relation("rsvp_user")
  createdEvents Event[]  @relation(name: "created_event")
  profile       Profile? @relation("profile_user")
}

Environment & setup

  • OS: Mac OS
  • Database: MySQL
  • Node.js version: v14.17.3

Prisma Version

prisma                  : 3.6.0
@prisma/client          : 3.7.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:37 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
nkrekowcommented, Jan 25, 2022

yup! CleanShot 2022-01-25 at 10 22 04@2x

2reactions
uvaluscommented, Jan 25, 2022

Yes

Read more comments on GitHub >

github_iconTop Results From Across the Web

update() returning { count: 1 } · Issue #5852 · prisma ... - GitHub
What happens if you run this Prisma Client query outside of a resolver in the same project? Do you still see the error?...
Read more >
Aggregation, grouping, and summarizing (Concepts) - Prisma
Aggregation, grouping, and summarizing. Prisma Client allows you to count records, aggregate number fields, and select distinct field values.
Read more >
Prisma Client API (Reference)
Prisma Client uses a database upsert for an upsert query when the query meets the following criteria: There are no nested queries in...
Read more >
CRUD (Reference) - Prisma
This page describes how to perform CRUD operations with your generated Prisma Client API. CRUD is an acronym that stands for: Create; Read;...
Read more >
Relation queries (Concepts) - Prisma
When you use select to return a subset of data from related records (for example, a user's posts), you can filter and sort...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found