Docs Menu

Docs HomeLaunch & Manage MongoDBMongoDB Atlas

How to Run Partial Match Atlas Search Queries

On this page

  • Required Access
  • Create the Atlas Search Index
  • Run a Case-Sensitive Partial Match Query

This tutorial describes how to create an index on the sample_mflix.movies collection and run partial string queries against the plot field. To return matches for partial string queries, you can use one of the following operators:

  • The autocomplete operator, which allows you to search the specified fields for a word or phrase that contains the sequence of characters that you specify with your query.

  • The phrase operator, which allows you to search the specified fields for documents that contain the terms in your query string at the distance you specify between the terms.

  • The regex operator, which allows you to search the specified fields for strings using regular expression.

  • The wildcard operator, which allows you to search the specified fields using special characters in your query to match any character.

This tutorial takes you through the following steps:

  1. Set up an Atlas Search index on the plot field in the sample_mflix.movies collection.

  2. Run Atlas Search query for a partial string against the plot field in the sample_mflix.movies collection using autocomplete, phrase, regex, and wildcard operators.

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.

In this section, you will create an Atlas Search index on the plot field in the sample_mflix.movies collection for running partial match queries against those fields.

1
  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 Atlas Search tab.

2
3
  • For a guided experience, select the Atlas Search Visual Editor.

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

4
  1. In the Index Name field, enter partial-match-tutorial.

    Note

    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.

5

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

6
7

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

8

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 on this page to set the language of the examples in this section.


You can use the autocomplete, phrase, regex, and wildcard operators to run a case-sensitive partial match query. This tutorial uses these operators to search for movies whose plot contain the specified partial string.

In this section, you will connect to your Atlas cluster and run the sample query using the operator against the plot field in the sample_mflix.movies collection.

←  How to Run Multilingual Atlas Search QueriesHow to Run Atlas Search Queries Across Collections →