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

200
Vistas
How to fetch a document from MongoDB inserted only within last few minutes?

I am using the below query to fetch the latest document.

const user = await Conversation.find({ isBot: false, to: from.slice(9), queryType: "template_preview" }).sort({ sentTime: -1 }).limit(1);

But the issue is this can also fetch old documents inserted long before. But for my use case I want the document inserted before few minutes say 5 min. What should be the exact query for this.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Try this one:

const user = await Conversation.find({ 
         isBot:false,
         sendTime:{
            $gte: timestamp of -5 min,
            $lte: timestamp (now)
         },
         queryType: "template_preview"
     }).sort({ sentTime: -1 });
over 4 years ago · Santiago Trujillo Denunciar
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