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

311
Vistas
PUT request BSONTypeError: Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer

I am trying to send a PUT request to the API but I get an error. I tried casting in DAO file but wasn't helpful. I tried the other solutions to this issue but nothing could help me.

json data

{   
"citizen_id": "62595e0a2bcb1344ed6ab683",
"user_id": "1320",
"name": "cctyv tesey",
"email": "testtesty@gmail.com",
"password": "abc123",
"nic": "921242340V",
"qualification": "a level",
"username": "tesy123",
"address": "4/3, isurupura road, kothalwala, kaduwela",
"profession": "software developer"}

citizenDAO.js

static async updateCitizens(userId, citizenId, date) {
    try {
      const updateCitizen = await citizens.updateOne(
        { user_id:userId,_id: ObjectId(citizenId)
        },
        { $set: { date: date  } },
      )

      return updateCitizen
    } catch (e) {
      console.error(`Unable to update the citizen: ${e}`)
      return { error: e }
    }
  }

citizen.controller.js

static async apiUpdateCitizens(req, res, next) {
try {
  const citizenId = req.body.citizen_id
  //const text = req.body.text
  const date = new Date()

  const citizenResponse = await CitizensDAO.updateCitizens(
    
    citizenId,
    req.body.user_id,
    date,
  )
  var { error } = citizenResponse
  if (error) {
    console.error(`Unable to update the citizen: ${error}`)
  } 

  if (citizenResponse.modifiedCount === 0) {
    throw new Error(
      "unable to update citizen - user may not be same",
    )
  }

  res.json({ status: "success" })
} catch (e) {
  res.status(500).json({ error: e.message })
}

}

about 4 years ago · Santiago Trujillo
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