1

So, In meteor, I am trying to count the number of documents created today. Obviouly the code below tries to match it to the time of the day along with the date.

var ct2 =  Bids.find({$and:[{bidder:currentUser},{createdAt:Date()}]}).count();

How do I go about finding the number of documents for today ?

Thanks in advance.

user1487244
  • 121
  • 1
  • 1
  • 9

2 Answers2

3

You might need to do something like this

Query to get last X minutes data with Mongodb

var ct2 =  Bids.find({
    $and: [
       { bidder: currentUser },
       {
           createdAt: { $gt: new Date(Date.now() - (1000 * 60 * 60 * 24)) }
       }
    ]
}).count();
Community
  • 1
  • 1
Kishor
  • 2,659
  • 4
  • 16
  • 34
1

By using moment js:

date=moment().add(-1,'days').toISOString();
val1 = checkdate1.substring(0, 11)
temp=val1+'23:59:59.'
val3=date.substring(20,25)
val4=temp+val3;
count = Bids.find({"createdAt": {$gt:new Date(val4)}}).count()
sravanthi
  • 247
  • 1
  • 6