Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

194
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda