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

121
Vistas
Finding data between two dates by using a query in mongoose

How would I write a query which checks the createdAt and finds all objects between 2022-05-22 and 2022-06-22? I tried the following code/ API, but it didn’t give back the right data :

getPoDetails = async (req, res, next) => {
    try {
        let fromDate = req.query.fromDate;
        let toDate = req.query.toDate;
        var findQry = {};
        if(fromDate && toDate) {
            findQry.createdAt = {$gte: new Date(fromDate), $lte: new Date(toDate)};
        }
        allmodels.poDetailsModel.find(findQry)
        .then(data => res.status(200).send(data))
        .catch(err => res.status(400).send(err));
    } catch (error) {
        next(error);
    }
}

API link : localhost:8000/getPoDetails?fromDate=2022-05-22&toDate=2022-06-22

about 4 years ago · Santiago Trujillo
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