I have been working on a blog web application where I aim to showcase posts on the main page. Currently, I am using MongoDB to fetch posts based on tags.
My goal is to have the content on the home page appear random and diverse, incorporating both the latest and most popular posts.
However, I have encountered an issue regarding duplicate data when retrieving additional posts.
My backend setup involves Express with Mongo as the database.
After scrolling through 2 pages, I noticed that I was receiving data that I had already seen before. I managed to address this in the front-end (using React).
Nevertheless, I am seeking a solution to handle this at the backend level, similar to what other websites do.
I came across this example. The aim is for the second request to provide new data while disregarding information retrieved in the first request (page).
db.test.aggregate([ { $match: { tags: { $in: ["python", "java"] } } }, { $sample: { size: 10 } }, { $project: { text: true } }]).toArray()