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:
About this Task
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.
Before you Begin
You must enable natural language querying.
Steps
The examples on this page use the sample_mflix.movies collection from the Atlas sample dataset.
Navigate to the Natural Language Query Bar
Select the Documents tab.
Click the Generate query button.
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.
Run the query
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.
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.
Example
Below are examples of prompts to help you understand expected results when using natural language prompts.
Prompt | Response | |
---|---|---|
|
| |
|
| |
|
|