Docs Menu
Docs Home
/
MongoDB Compass
/ /

Prompt a Natural Language Query

On this page

  • About this Task
  • Before you Begin
  • Steps
  • Example
  • Next Steps
  • Learn More

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.

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 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.

You must enable natural language querying in Compass.

1
  1. Select the Documents tab.

  2. Click the Generate query button.

The Natural Language Query Bar displays.

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

Query with Natural Language

Back

Enable

Next

Prompt Aggregation