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.您可以使用MongoDB Compass使用自然语言生成聚合查询。Compass使用AI根据您提供的提示生成聚合。使用自然语言进行查询可以成为一个有用的起点,并帮助您学习编写MongoDB查询。
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.当您在Compass中使用自然语言查询数据时,提示文本和有关MongoDB模式的详细信息将发送给Microsoft和OpenAI进行处理。数据不会存储在任何第三方存储系统中,也不会用于训练AI模型。
This software uses generative artificial intelligence. It is experimental and may give inaccurate results. Your use of this software is subject to MongoDB's:该软件使用生成式人工智能。这是实验性的,可能会给出不准确的结果。您对本软件的使用受MongoDB的约束:
You can also provide natural language prompts on the documents tab.您还可以在文档选项卡上提供自然语言提示。This page uses the sample_mflix.movies collection from the Atlas sample dataset.此页面使用Atlas样本数据集中的sample_mflix.movies集合。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.很难预测Compass AI返回的查询或管道的复杂性。您可能需要调整“MAX TIME MS”查询栏选项,以允许更长的查询处理时间或防止长时间运行的查询。For details, see Adjust Maximum Time for Query Operations.有关详细信息,请参阅调整查询操作的最大时间。
Before you Begin开始之前
You must enable natural language querying in Compass.您必须在Compass中启用自然语言查询。
Steps步骤
Navigate to the Natural Language Query Bar导航到自然语言查询栏
Select the Aggregations tab.选择“聚合”选项卡。Click the Generate aggregation button.单击“生成聚合”按钮。
The Natural Language Query Bar displays.将显示“自然语言查询栏”。
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.按enter键或单击“生成聚合”按钮。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.在运行查询之前,请确保彻底检查每个阶段的语法。确保返回的管道具有与所需用例匹配的字段和阶段。Warning
Some aggregation operators, like一些聚合运算符,如$mergeand$out, can modify your collection's data.$merge和$out,可以修改集合的数据。If your aggregation pipeline contains operators that can modify your collection's data, you are prompted for confirmation before the pipeline is executed.如果聚合管道包含可以修改集合数据的运算符,则会在执行管道之前提示您进行确认。Press enter or click the Run button to execute the pipeline.按enter键或单击“运行”按钮执行管道。
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.反馈不会用于训练任何AI模型。
Examples示例
Below are examples of prompts to help you understand expected results when using natural language prompts for aggregation.以下是使用自然语言提示进行聚合时帮助您理解预期结果的提示示例。
| |
| |
|