Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

195
Views
How to get record based upon two range of date and time in mongodb with Aggregation?

i'm trying to $match two $addFields dates (FromDate and ToDate) to get record between given date and time but i am faceing issue with $match two dates.

  const Objdata = await Events.aggregate([
                      {
                        $lookup: {
                          from: "MeetingReminderSetting",
                          let: {
                            flag: false,
                            cid: "$ClientID",
                            esd: "$EventStartDtByTimeZone",
                          },
                          pipeline: [
                            {
                              $match: {
                                $expr: {
                                  $and: [
                                    { $eq: ["$IsDeleted", "$$flag"] },
                                    { $eq: ["$ClientID", "$$cid"] },
                                  ],
                                },
                              },
                            },
                          ],
                          as: "p1",
                        },
                      },
                      {
                        $unwind: {
                          path: "$p1",
                          preserveNullAndEmptyArrays: false,
                        },
                      },
                      {
                        $addFields: {
                          FromDate: {
                            $dateAdd: {
                              startDate: new Date("2022-01-01T00:00:00.000+00:00"),
                              unit: "hour",
                              amount: 24,
                            },
                          },
                          Todate: {
                            $dateAdd: {
                              startDate: {
                                $dateAdd: {
                                  startDate: new Date("2022-01-01T00:00:00.000+00:00"),
                                  unit: "hour",
                                  amount: 24,
                                },
                              },
                              unit: "minute",
                              amount: 10,
                            },
                          },
                        },
                      },
                      //---issue facing------//
                      **{
                        $match: {
                          EventStartDtByTimeZone: {
                            $gte: "$FromDate",
                            $lte: "$Todate",
                          },
                        },
                      },**
                    //----------------//
                    ]);

it working when i give static date in $gte and $lte. but it not working when i apply date from >$addFields i used multiple cases like i change date in $dateToString and than campare but it don't work

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!