1

My collections having DATE key ,that is in String format, so how to query for finding giving date count or i can find how many data is there: I tried one experiment but it is not working ;

db.colName.find({"date": {$gte: "Tue Aug 30 16:43:22 IST 2016",$lt: "Tue Aug 30 16:43:22 IST 2016"}})

Please suggest is it possible in MongoDB or how how can i find my desire result?

TB.M
  • 363
  • 3
  • 8
  • 26
  • 2
    For best results, convert the string representation of the date to a proper Date type as in this question http://stackoverflow.com/questions/10942931/converting-string-to-date-in-mongodb – chridam Jan 03 '17 at 07:36

2 Answers2

0

You need to get all data, parse all dates in the right format and then filter it.

If you are using javascript result save in some variable and do this...

result.map(function(singleResult) {
  Date.parse(singleResult.date)
  return singleResult
});
Matej Maloča
  • 964
  • 7
  • 12
-1

You can do it with ISODate

db.colName.find({"date": {$gte: ISODate("2016-08-30 16:43:22"),$lt: ISODate("2016-08-30 16:43:22")}})

Same can be done with javascript Date also

db.colName.find({"date": {$gte: new Date("2016-08-30 16:43:22"),$lt: new Date("2016-08-30 16:43:22")}})
Rahul Kumar
  • 2,781
  • 1
  • 21
  • 29