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

165
Visualizações
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 Respostas
Responde à pergunta

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 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