Organizational Research By

Surprising Reserch Topic

inserting and querying date with mongodb and nodejs


inserting and querying date with mongodb and nodejs  using -'javascript,node.js,mongodb,date'

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?

Thanks.
    
asked Sep 18, 2015 by mca.agarwal
0 votes
83 views



Related Hot Questions



Government Jobs Opening


...