I have a MongoDB database and a React web page that shows the content using http requests to my Node.js server. This Node.js uses mongoose to communicate with the DB. The react web page shows up to 10 entries per page and it is slow when the database gets big:
What Node.js is doing:
router.get("/", async (req, res) => {
const movies = await Movie.find()
.select("-__v")
.sort("name");
res.send(movies);
});
As you can see, Node.js returns all the database and the front end React only displays the 10 entries depending on the page the user is viewing.
It would be optimal to fetch from the database only 10 entries depending on the page the user is looking at.
How can I do that?
Thanks