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

158
Vistas
How to test this block of code with POSTMAN?

I am currently working on a delete function on the backend so that only authorized users can delete their reviews if they want to. I am currently trying to test it through POSTMAN but I am getting the error "Argument passed in must be a single String of 12 bytes or a string of 24 hex characters".

Currently, my POSTMAN is set up where the user is already logged in and I used their auth token and set it as the authorization header for the delete function

router.delete("/delete/:reviewId", requireAuth, async (req, res, next) => {
  const { user } = req
  const { reviewId } = req.params
  const review = await Review.findById(reviewId)
  console.log(reviewId)
  console.log(review)
  if (!review) {
    return response.status(422).json({ error: "Cannot find review" })
  }
  console.log(review.author._id.toString(), typeof review.author._id.toString())
  console.log(user.id, typeof user.id)
  if (review.author._id.toString() === user.id) {
    console.log("if is working")
    try {
      const removedReview = await review.remove()
      console.log("deleted review")
      const userUpdate = await User.updateOne(
        { _id: user.id },
        { $pull: { reviews: reviewId } }
      )
      res.json(removedReview)
    } catch (err) {
      next(err)
    }
  }
})

POSTMAN setup image

I currently don't have enough rep to embed the image into the post.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This issue is surely related with _id that is sent to the mongoDB. You should check the validity of all _ds you used in this code block. The _d must be type of ObjectID to be precise. You can use typeof operator to determine its type. If it is other than ObjectID simply convert it.

var ObjectId = require('mongodb').ObjectID; 
Model.findById(new ObjectId(yourId))

Let me know if it helped:)

about 4 years ago · Juan Pablo Isaza 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