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

216
Views
Why is this query working in the mongo shell but not the node mongo driver?

I'm successfully running this query in the shell:

db.hourlydatas.find({'timeseries':ObjectId('1234')})

Trying to translate it to the mongo driver:

MongoClient.connect(config.db, function(err, db) {
// Use the admin database for the operation

var collection = db.collection('hourlydatas');

collection.find({'timeseries':'1234'}).toArray(function(err, docs) {
//   assert.equal(err, null);
console.log("Found the following records");
console.log(docs);
// callback(docs);
});      

});

This does not return any documents, I assume because I'm not converting the string to an objectID. Is this possible in the driver?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Try this

 var ObjectId = require('mongodb').ObjectID;var collection = db.collection('hourlydatas'); collection.find({'timeseries':ObjectId('1234')}).toArray(function(err,docs) {...})
over 4 years ago · Santiago Trujillo Report

0

It should work, are you sure you are connecting to the same DB? check if both connections are to test or prod... I once wasted a lot of time on this just to find at the end that my mongo-shell was connected to prod while node was connecting to test.

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