Docs Menu

Docs HomeMongoDB Atlas

How to Use Autocomplete with Atlas Search

On this page

  • Required Access
  • Define an Index with Autocomplete
  • Run an Autocomplete Query
  • Continue Learning

This tutorial describes how to create an Atlas Search index that enables autocomplete queries. In the following examples, the index enables autocomplete operators to query the specified field values.

Both examples take you through the following steps:

  1. Set up an Atlas Search index with autocomplete data type for the sample_mflix.movies collection.

  2. Run Atlas Search queries against the specified fields in the sample_mflix.movies collection for an inputted sequence of characters.

Before you begin, ensure that your Atlas cluster meets the requirements described in the Prerequisites.

To create an Atlas Search index, you must have Project Data Access Admin or higher access to the project.

You can use the Atlas Search autocomplete type to index text values in string fields for autocompletion. You can configure an autocomplete type to satisfy a variety of use cases. To learn more about the configuration options available for the autocomplete type, such as tokenization strategy and diacritic folding, see Configure autocomplete Field Properties. You can query fields indexed as autocomplete type only using the autocomplete operator.

In this section, you will create an Atlas Search index that indexes the title and plot fields for autocompletion using the edgeGram tokenization strategy.

  1. If it is not already displayed, select the organization that contains your desired project from the Organizations menu in the navigation bar.

  2. If it is not already displayed, select your desired project from the Projects menu in the navigation bar.

  3. Click your cluster's name.

  4. Click the Search tab.

  • For a guided experience, select Visual Editor.

  • To edit the raw index definition, select JSON Editor.

  1. In the Index Name field, enter autocomplete-tutorial.


    If you name your index default, you don't need to specify an index parameter when using the $search pipeline stage. Otherwise, you must specify the index name using the index parameter.

  2. In the Database and Collection section, find the sample_mflix database, and select the movies collection.


You can use the Visual Editor or the JSON Editor in the Atlas user interface to create the index.


A modal window appears to let you know your index is building. Click the Close button.


The index should take about one minute to build. While it is building, the Status column reads Build in Progress. When it is finished building, the Status column reads Active.

Use the Select your language drop-down menu to set the language of the example on this page.

The autocomplete operator performs a search for a word or phrase that contains a sequence of characters from an incomplete input string. You can use the autocomplete operator with search-as-you-type applications to predict words with increasing accuracy as characters are entered in your application's search field. autocomplete returns results that contain predicted words based on the tokenization strategy specified in the index definition for autocompletion. The fields that you intend to query with the autocomplete operator must be indexed with the How to Index Fields for Autocompletion data type in the collection's index definition.


Atlas Search might return inaccurate results for queries with more than three words in a single string.

Follow along with this video tutorial walk-through that demonstrates how to use the Atlas Search autocomplete operator and JavaScript to build a frontend form element that suggests data to the user.

Duration: 30 minutes

←  How to Sort Your Atlas Search ResultsHow to Use Facets with Atlas Search →
Share Feedback
© 2023 MongoDB, Inc.


  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2023 MongoDB, Inc.