Filtering mongodb data with month and day input

PHOTO EMBED

Fri Jun 11 2021 05:17:27 GMT+0000 (Coordinated Universal Time)

Saved by @tapasdash #nodejs #mongoose #mongodb #aggregate

const dateFilter = asyncHandler(async (req, res) => {
  const month = 7;
  const day = 13;
  const feedbacks = await Feedback.find({
    $expr: {
      $or: [
        {
          $and: [
            { $eq: [{ $month: "$birthday" }, month] },
            { $eq: [{ $dayOfMonth: "$birthday" }, day] },
          ],
        },
        {
          $and: [
            { $eq: [{ $month: "$anniversary" }, month] },
            { $eq: [{ $dayOfMonth: "$anniversary" }, day] },
          ],
        },
      ],
    },
  });
  res.send(feedbacks);
});
content_copyCOPY