Prompt a Natural Language Aggregation
You can use MongoDB Compass to generate aggregation queries using natural language. Compass 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.
About this Task
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:
You can also provide natural language prompts on the documents tab.
This page uses the sample_mflix.movies collection from the Atlas sample dataset.
It can be difficult to predict the complexity of the query or pipeline returned by the Compass AI. You may need to adjust the MAX TIME MS query bar option to either allow longer query processing time or prevent long-running queries. For details, see Adjust Maximum Time for Query Operations.
Before you Begin
Steps
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.
Press enter or 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.
Example
Below are examples of prompts to help you understand expected results when using natural language prompts for aggregation.
Prompt | Response | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Count the movies that have a release year of 1999 |
| ||||||||||||||||||||||||
Which comedy genre movie has the most awards? |
| ||||||||||||||||||||||||
How many movies have a imdb.rating > 4? |
|