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

209
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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