Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongoose get records that were created_at in the last 5 minutes using find()

What's the proper way of retrieving the entries that were created in the last 5 minutes if I'm currently using Model.find()?

like image 236
MB. Avatar asked Nov 24 '25 15:11

MB.


1 Answers

Calculate the time of five minutes ago and then use the $gte operator:

var d = new Date();
d.setMinutes(d.getMinutes()-5);
Model.find({created_at: {$gte: d}}, callback);
like image 197
JohnnyHK Avatar answered Nov 28 '25 17:11

JohnnyHK