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?
Try this
var ObjectId = require('mongodb').ObjectID;var collection = db.collection('hourlydatas'); collection.find({'timeseries':ObjectId('1234')}).toArray(function(err,docs) {...})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.