Atlas search - searchBefore return the same documents as searchAfter

I’m working on a pagination solution for atlas search based on this community link and this page
When I was testing it, I found that the searchAfter works ok, I selected the latest pagination token from my previous query and return the next results, but the searchBefore, with the same pagination token returned the same results as searchAfter.

My atlas version is mongodb/atlas:v1.14.2

Hi @Jose_Salina , can you share an example of your query? This may be caused by multiple documents having the same score, so please ensure that you have added a unique sort field.

You can learn more in the docs here:

If multiple documents in the results have identical scores, Atlas Search returns arbitrarily ordered results. To return documents in a determined order, use a unique field to sort your query results.

1 Like

Thanks, you are right, I wasn’t sorting by any field and the pagination token wasn’t working property, adding a unique sort improve this. Thanks

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.