Docs HomeMongoDB Compass

Export Query to Specific Language将查询导出为特定语言

New in version 1.15.0

You can export queries created in the query bar to one of the supported languages; Java, Node, C#, Python 3, Ruby, Go, Rust, and PHP. 您可以将在查询栏中创建的查询导出为支持的语言之一;Java、Node、C#、Python3、Ruby、Go、Rust和PHP。This feature allows you to reformat and use MongoDB Compass queries in your application.此功能允许您在应用程序中重新格式化和使用MongoDB Compass查询。

Procedure过程

  1. After constructing a query in the query bar, click to the right of the Reset button.查询栏中构造查询后,单击“重置”按钮右侧的
  2. Click the Export to Language button </>:单击“导出为语言”按钮</>

    Query bar export dropdown menu
  3. In the Export Query To: dropdown, select your desired language:在“将查询导出到:”下拉列表中,选择所需的语言:

    Query bar language select

    The My Query pane on the left displays your query in mongo shell syntax.左侧的“我的查询”窗格以mongoshell语法显示您的查询。

    The pane to the right displays your query in the language selected.右侧的窗格以所选语言显示您的查询。

  4. (Optional): Check the Include Import Statements option to include the required import statements for the language selected.:选中“包含导入语句”选项以包含所选语言所需的导入语句。
  5. (Optional): Check the Include Driver Syntax option to include application code for the language selected. :选中“包含驱动程序语法”选项以包含所选语言的应用程序代码。If you include driver syntax, the copyable code reflects project, sort, maxtimems, collation, skip and limit options.如果包含驱动程序语法,则可复制代码会反映projectsortmaxtimemscollationskiplimit选项。
  6. Click at the top-right of the formatted query to copy the query for the selected language to your clipboard. 单击格式化查询的右上角的,将所选语言的查询复制到剪贴板。You can now easily integrate and execute your created query in your application.现在,您可以在应用程序中轻松地集成和执行创建的查询。

    Copy button clicked in Export Query to Language modal
  7. Click Close to return to the Documents Tab.单击“关闭”返回到“文档”选项卡