How to Paginate Query Results
Atlas Search queries might return many results. To make navigating results easier, you can either use pagination to divide results into discrete pages or use cursor iteration to view all the results for your query.
The following tutorials take you through the steps for paginating your query results:
The Paginate the Results page describes how to use the
$search
searchAfter
andsearchBefore
options to build functions similar to "Next Page", "Previous Page", "Load More", and infinite scroll in your application.To retrieve the paginated results non-sequentially and view the total number of search results for a query, you can use the
$skip
and$limit
stages after the$search
stage. This method might take longer than expected for large query results. To learn more, see the How to Divide Query Results into Discrete Pages tutorial.The How to Iterate Your Cursor to View All Results tutorial demonstrates how to create an index and iterate the cursor until it is exhausted to return all results for a query.