Docs Menu
Docs Home
/
Atlas
/ /

Prompt a Natural Language Query

You can use Atlas to generate queries using natural language. Atlas uses AI to generate queries based on prompts you provide. Querying with natural language can be a helpful starting point and assist you in learning to write MongoDB queries.

Note

When you query your data using natural language in Compass, the text of your prompts and details about your MongoDB schemas are sent to Microsoft and OpenAI for processing. Your data is not stored on any third party storage systems or used to train AI models.

This software uses generative artificial intelligence. It is experimental and may give inaccurate results. Your use of this software is subject to MongoDB's:

  • Terms of Use

  • Acceptable Use Policy

  • Privacy Policy

You can query with natural language to create both queries and aggregations. If your prompt results in an aggregation, you are automatically redirected to the Aggregations tab and a pop-up message displays indicating that your prompt requires aggregation stages.

You can also provide natural language prompts on the aggregations tab.

You must enable natural language querying.

The examples on this page use the sample_mflix.movies collection from the Atlas sample dataset.

1
  1. Select the Documents tab.

  2. Click the Generate query button.

  3. If you're generating a natural language query for the first time, Atlas displays a modal that states Use natural language to generate queries and pipelines modal. To use natural language querying, you must click the Use Natural Language button and accept the MongoDB Acceptable Use Policy and Privacy Policy.

    Accept the terms and conditions for natural language querying
2

Type a natural language prompt for your collection into the query bar. For example: Which movies were released in 2000?

  1. Press enter or click the Generate query button.

  2. A filter query populates in the Filter bar.

3
  1. Before running the query, make sure to thoroughly review the syntax in the Filter bar. Ensure the returned query has the fields and operators that match your desired use case.

  2. Press enter or click the Find button to execute the query.

The results populate in the documents view.

Tip

You can optionally provide feedback by clicking the or icon by the Natural Language Query Bar and provide details on your experience.

Your feedback is not used to train any AI models.

Below are examples of prompts to help you understand expected results when using natural language prompts.

Prompt
Response

Which movies have a "PG" rating?

{"rated": "PG"}

Which movies include "David Mamet" in the writers array field?

{"writers": "David Mamet"}

Which movies have a runtime greater than 90?

{"runtime": {$gt: 90}}

Prompt a Natural Language Aggregation

Back

Enable

On this page