user1487244
user1487244

Reputation: 121

Finding Documents created today

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.

Upvotes: 1

Views: 1192

Answers (2)

sravanthi
sravanthi

Reputation: 247

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()

Upvotes: 1

Kishor
Kishor

Reputation: 2677

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();

Upvotes: 3

Related Questions