I m making an aggregation query to my mongoDB using a text index, I implemented a pagination system but it’s not working as expected
At first I thought it was related to the other sort field but it’s seems like the id alone is not working properly
Also I m pretty sure a pagination system is possible with multiple sort parameter
so here is the aggregation pipeline (it’s in javascript)
pipeline: [
{
$match: {
$text: { $search: `"${key}"` },
},
},
{
$match: {
...(query.previousId ? { _id: { $gt: query.previousId } } : {}),
},
},
{
$sort: {
_id: 1,
created_t: -1,
},
},
{
$limit: 10,
},
],
so it’s using the text index, and I want my pagination to work using the previous last id
it’s “working” but when I use the previousId, I can see some of the previous result coming in the next result, and I don’t known how to fix this with mongo
Do someone have an idea about how mongo index and sorting work and how I can use it properly with my id ?
Thanks in advance