Prompt a Natural Language Query
You can use MongoDB Compass to generate queries using natural language. Compass 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.
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 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 displays indicating your prompt requires aggregation stages.
You can also provide natural language prompts on the aggregations 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
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 | |
---|---|---|
Which movies have a "PG" rating? |
| |
Which movies include "David Mamet" in the writers array field? |
| |
Which movies have a runtime greater than 90? |
|