Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

97
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!