Cant find the entry between Two dates even though the entry is present in the db

for (let i = 0; i < 12; i++) {
const monthStartDate = todayUTC.month(i).startOf(‘month’).toDate();
const monthEndDate = todayUTC.month(i).endOf(‘month’).toDate();

  // Retrieve attendance data for the current month for the specified student


  const attendanceForMonth = await Attendance.find({
      students: studentId,
      date: {
          $gte: monthStartDate,
          $lte: monthEndDate

I have and entry like

“_id”: “66145402879dafa426d3add6”,
“classLevel”: “65dcc9a3fead4ed58f0dd32f”,
“section”: “65de3d0b0b186d07577218e4”,
“date”: “2024-04-08T18:00:00.000Z”,
“status”: “absent”,
“students”: “6604a954ad30e1912c886fd0”,
“createdAt”: “2024-04-08T20:30:58.719Z”,
“updatedAt”: “2024-04-09T10:53:11.840Z”,
“__v”: 0

but whatever I try I can’t find the entry.

It’s return empty even though I have the entry on april


Why is that?

Please read Formatting code and log snippets in posts and update your sample document.

I suspect a type discrepancy between your query which is a Date and your data that looks like strings. The types and values must match.