Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

251
Visualizações
Updating a prisma field using the "where" clause causes an error

I'm having this error when updating a field depending on the id of the model but I'm getting a Invalid prisma.resource.update() invocation: error.

This is my query:

const upvote = await prisma.resource.update({
  where: {
    id: body.resourceID,
  },
  data: {
    totalUpvotes: {
      increment: 1
    },
    userUpvoted: true,
  },
});

When I run the same query but use a string value instead of the body.resource variable,

const upvote = await prisma.resource.update({
  where: {
    id: "cl5njhgc90435e8sx2o6d",
  },
  data: {
    totalUpvotes: {
      increment: 1
    },
    userUpvoted: true,
  },
});

I'm getting the desired output. Can you tell me why this might be happening

I'm using NextJS, Prisma and PlanetScale for this application

Following is the full output of the error.

Request error PrismaClientValidationError:
Invalid `prisma.resource.update()` invocation:

{
  where: {
?   id?: String
  },
  data: {
    totalUpvotes: {
      decrement: 1
    },
    userUpvoted: false
  }
}

Argument where of type ResourceWhereUniqueInput needs at least one argument. Available args are listed in green.

Note: Lines with ? are optional.

    at Document.validate (C:\Users\Ammaar\resourcehub\node_modules\@prisma\client\runtime\index.js:48195:20)
    at PrismaClient._executeRequest (C:\Users\Ammaar\resourcehub\node_modules\@prisma\client\runtime\index.js:50632:17)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async PrismaClient._request (C:\Users\Ammaar\resourcehub\node_modules\@prisma\client\runtime\index.js:50572:18)
    at async __WEBPACK_DEFAULT_EXPORT__ (webpack-internal:///(api)/./pages/api/meta/downvote.js:17:28)
    at async Object.apiResolver (C:\Users\Ammaar\resourcehub\node_modules\next\dist\server\api-utils\node.js:179:9)
    at async DevServer.runApi (C:\Users\Ammaar\resourcehub\node_modules\next\dist\server\next-server.js:381:9)
    at async Object.fn (C:\Users\Ammaar\resourcehub\node_modules\next\dist\server\base-server.js:488:37)
    at async Router.execute (C:\Users\Ammaar\resourcehub\node_modules\next\dist\server\router.js:213:36) {
  clientVersion: '4.0.0'
}

Thanks in advance.

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

Based on the error you're receiving and your code, body.resourceID is being evaluated to undefined within your code. Make sure body.resourceID is a string by the time the code executes - is it possible your body contains a variable named something other than resourceID, and it's just a typo?

about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda