I need some help finding a record by date in mongodb and nodejs.
I add the date to the json object in a scraping script as follows:
jsonObj.last_updated = new Date();
This object is inserted into mongodb. I can see it as follows:
"last_updated" : "2014-01-22T14:56:59.301Z"
Then in my nodejs script I do a findOne():
var jObj = JSON.parse(line.toString());
collection.findOne(jObj,function(err, doc) {
if (doc){
console.log(doc._id);
} else {
console.log('not found');
}
});
The object is not found. If I remove the last_updated field from the object it is found so it is definitely where the problem is.
If I isolate the field as follows:
collection.findOne({last_updated: '2014-01-22T14:56:59.301Z'},function(err, doc) {
if (doc){
console.log(doc._id);
} else {
console.log('not found');
}
});
Nothing comes back either. What am I doing wrong please?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…