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.您可以使用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 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.此页面使用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 Documents tab.选择“文档”选项卡。Click the Generate query 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. For example: 在查询栏中键入集合的自然语言提示。例如:Which movies were released in 2000?
Press enter or click the Generate query button.按enter键或单击“生成查询”按钮。A filter query populates in the Filter bar.筛选器查询将填充到“筛选器”栏中。
Tip
It is also possible to paste SQL or queries from application code into the Natural Language Query Bar.也可以将应用程序代码中的SQL或查询粘贴到“自然语言查询栏”中。
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.按enter键或单击“查找”按钮执行查询。
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.反馈不会用于训练任何AI模型。
Example示例
Below are examples of prompts to help you understand expected results when using natural language prompts.以下是使用自然语言提示时帮助您理解预期结果的提示示例。
| |
| |
|