Prompt a Natural Language Aggregation
You can use Atlas to generate aggregation queries using natural language. Atlas uses AI to generate aggregations 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 also provide natural language prompts on the documents 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 Aggregations tab.
Click the Generate aggregation 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.
Type a question about your collection
Type a natural language prompt for your collection into the query
bar. Aggregation pipeline prompts usually have an aggregation verb
such as count, average, or sum with logical conditions. For
example: How many movies have more than 3 writers
in the writers array?
Press enter or click the Generate aggregation button.
An aggregation pipeline populates in the Pipeline bar. You can scroll down to see the syntax of each stage.
Run the aggregation
Before running the query, make sure to thoroughly review the syntax of each stage. Ensure the returned pipeline has the fields and stages that match your desired use case.
Click the Run button to execute the pipeline.
The results populate in the aggregations 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.
Examples
Below are examples of prompts to help you understand expected results when using natural language prompts for aggregation.
Prompt | Response | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
| ||||||||||||||||||||||||
|
| ||||||||||||||||||||||||
|
|