This tutorial describes how to return all results for an Atlas Search query by
iterating your cursor until it is exhausted. By default, some Atlas Search
mongosh and MongoDB Compass print up to the first 20
documents in the results. To view all results at once, we recommend that
you iterate your cursor until it is exhausted. To demonstrate how to
iterate your cursor to view all results, this tutorial takes you through
the following steps:
Set up an Atlas Search index with dynamic mapping on the
Run an Atlas Search query that iterates your cursor until it is exhausted to retrieve all documents that contain the term
To create an Atlas Search index, you must have
Project Data Access Admin or higher access to the project.
If it is not already displayed, select the organization that contains your desired project from the Organizations menu in the navigation bar.
If it is not already displayed, select your desired project from the Projects menu in the navigation bar.
Click your cluster's name.
Click the Atlas Search tab.
In the Index Name field, enter
If you name your index
default, you don't need to specify an
indexparameter when using the $search pipeline stage. Otherwise, you must specify the index name using the
In the Database and Collection section, find the
sample_mflixdatabase, and select the
The following index definition dynamically indexes the fields of supported types in the collection. You can use the Atlas Search Visual Editor or the Atlas Search JSON Editor in the Atlas user interface to create the index.
➤ Use the Select your language drop-down menu to select the MongoDB client that you want to use to run the example queries on this page.
In this section, you connect to your Atlas cluster and run
queries against the
title field in the
collection to search for the term
Summer with the text operator. The collection includes over 75 documents that
contain the term
Summer in the title, but by default, some Atlas Search
clients print only the top 20 results for the query.
To view all the results for the query term at once, you iterate through your cursor until you exhaust the cursor.