Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

259
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda