Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

208
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda