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

152
Views
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 answers
Answer question

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 Report
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!