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

146
Vistas
fetch the recently added 10 recods from mogodb in express,js

i am trying to create a api that can fetch recently added 10 records every time the api is called from the data base is there a method to do that

i have this code which can access all the records how i limit only the first 10

app.get("/questapi", function (req, res) {
    mydb
      .collection("questions")
      .find({})
      .toArray(function (err, data) {
        if (err) throw error;
        res.send(data);
      });
  });

every time i call the api it should get recently added 10 i am fetching from mogodb

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

0

Try this,

app.get("/questapi", function (req, res) {
    mydb
      .collection("questions")
      .find()
      .limit(10);  //here you can limit how many elements you want to retrieve
      .toArray(function (err, data) {
        if (err) throw error;
        res.send(data);
      });
  });
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