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

203
Vistas
mongodb update fails due to _id without the "ObjectId" text

I have a script that identified two records that I need to update. My query returned the two _id values as: 62bdca65a69a2cdf17978992 and 62c06c18d694a13c4a29c078. I generated update the statements:

db.people.updateOne({_id: ObjectId('62bdca65a69a2cdf17978992')}, {$set: {dept: 22}});
db.people.updateOne({_id: ObjectId('62c06c18d694a13c4a29c078')}, {$set: {dept: 22}});

Only one got updated and examination of the data showed that one has the _id: 62bdca65a69a2cdf17978992 and the other has the _id as ObjectId('62c06c18d694a13c4a29c078').

  1. Can I somehow determine if the "ObjectId" part of the _id exists so that I can dynamically include or exclude that in my update?
  2. Can I write the update statement in a generic way so both get updated?
about 4 years ago · Juan Pablo Isaza
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