I have data stored in my database that I need to query for entries from yesterday. However, when I try the following code:
momentendYest', moment().startOf('day').subtract(1,'day').toDate()
it returns today's date at 7am instead. Can someone help me figure this out?
My goal is to do something like this:
const yesterdayRecords = await Record.find({
category: {
$regex: new RegExp(title, "i"),
},
createdAt: {
$gte: startOfYesterday,
$lt: endOfYesterday,
},
What changes should I make to ensure that I query data specifically from yesterday starting at 12am and ending at 11:59pm?