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

98
Vistas
Mongo DB is not updated by id

i'm trying to update mongo db document with mongo db driver on node js, the log show that it's updated but the data is not updated, i'm trying to get the data to get updated with id document and the document is not updated, but when i use another field as a variable to search the document, the document is updated.

var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://192.168.1.200:27017/";

MongoClient.connect(url, function(err, db) {
  if (err) throw err;
  var dbo = db.db("monitoring");
  var myquery = { _id : "62e5e171f38e161d6e905772" };
  var newvalues = { $set: { status: "1" } };
  dbo.collection("hosts").updateOne(myquery, newvalues, function(err, res) {
    if (err) throw err;
    console.log("1 document updated");
    db.close();
  });
});

Picture of the data: enter image description here

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

_id property in MongoDB is not of type String, it's of type ObjectId. Try this:

const ObjectID = require('mongodb').ObjectID;   
...
const myquery = { _id : new ObjectId("62e5e171f38e161d6e905772") };
about 4 years ago · Santiago Trujillo 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