使用 Azure 存储资源管理器管理 Azure Cosmos DB 资源Manage Azure Cosmos DB resources by using Azure Storage Explorer

可使用 Azure 存储资源管理器连接到 Azure Cosmos DB。You can use Azure Storage explorer to connect to Azure Cosmos DB. 借助此功能,可通过 Windows、macOS 或 Linux 连接到托管在 Azure 和主权云上的 Azure Cosmos DB 帐户。It lets you connect to Azure Cosmos DB accounts hosted on Azure and sovereign clouds from Windows, macOS, or Linux.

使用相同的工具在一个位置管理不同的 Azure 实体。Use the same tool to manage your different Azure entities in one place. 可管理 Azure Cosmos DB 实体、操作数据、更新存储过程和触发器,还可更新其他 Azure 实体(例如存储 Blob 和队列)。You can manage Azure Cosmos DB entities, manipulate data, update stored procedures and triggers along with other Azure entities like storage blobs and queues.

Azure 存储资源管理器支持为 SQL、MongoDB、图形和表 API 配置的 Cosmos 帐户。Azure Storage Explorer supports Cosmos accounts configured for SQL, MongoDB, Graph, and Table APIs. 有关详细信息,请转到 Azure 存储资源管理器中的 Azure Cosmos DBGo to Azure Cosmos DB in Azure Storage Explorer for more information.

先决条件Prerequisites

具有 Cosmos 帐户,且该帐户带有用于 MongoDB 的 SQL API 或 Azure Cosmos DB API。A Cosmos account with a SQL API or an Azure Cosmos DB API for MongoDB. 如果没有帐户,可在 Azure 门户中创建一个。If you don't have an account, you can create one in the Azure portal. 有关详细信息,请参阅 Azure Cosmos DB:使用 .NET 和 Azure 门户生成 SQL API Web 应用See Azure Cosmos DB: Build a SQL API web app with .NET and the Azure portal for more information.

安装Installation

若要安装最新版本的 Azure 存储资源管理器,请参阅 Azure 存储资源管理器To install the newest Azure Storage Explorer bits, see Azure Storage Explorer. 我们支持 Windows、Linux 和 macOS 版本。We support Windows, Linux, and macOS versions.

连接到 Azure 订阅Connect to an Azure subscription

  1. 安装 Azure 存储资源管理器后,在左侧窗格中选择插件图标 。After you install Azure Storage Explorer , select the plug-in icon on the left pane.

    显示左侧窗格中的插件图标的屏幕截图。

  2. 在“添加 Azure 帐户”中选择值“Azure 中国”,然后单击“登录”。Select the value of Azure China in Add an Azure Account , and then click Sign-in .

    “连接到 Azure 存储”窗口的屏幕截图,其中显示已选择“添加 Azure 帐户”单选按钮,还包含“Azure 环境”下拉菜单。

  3. 在“Azure 登录”对话框中,选择“登录”,然后输入 Azure 凭据。In the Azure Sign-in dialog box, select Sign in , and then enter your Azure credentials.

    “登录”窗口的屏幕截图,其中显示在何处输入 Azure 订阅的凭据。

  4. 从列表中选择订阅,然后选择“应用”。Select your subscription from the list, and then select Apply .

    “帐户管理”窗格的屏幕截图,其中显示订阅列表和“应用”按钮。

    资源管理器窗格会更新,并显示所选订阅中的帐户。The Explorer pane updates and shows the accounts in the selected subscription.

    “资源管理器”窗格的屏幕截图,该窗格已更新为显示所选订阅中的帐户。

    Cosmos DB 帐户已连接到 Azure 订阅。Your Cosmos DB account is connected to your Azure subscription.

使用连接字符串连接到 Azure Cosmos DBUse a connection string to connect to Azure Cosmos DB

可使用连接字符串连接到 Azure Cosmos DB。You can use a connection string to connect to an Azure Cosmos DB. 此方法仅支持 SQL 和表 API。This method only supports SQL and Table APIs. 请按照以下步骤,使用连接字符串进行连接:Follow these steps to connect with a connection string:

  1. 在左侧树中找到“本地和附加”,右键单击“Cosmos DB 帐户”,然后选择“连接到 Cosmos DB” 。Find Local and Attached in the left tree, right-click Cosmos DB Accounts , and then select Connect to Cosmos DB .

    使用连接字符串连接到 Azure Cosmos DB

  2. 在“连接到 Cosmos DB”窗口中:In the Connect to Cosmos DB window:

    1. 从下拉菜单中选择 API。Select the API from the drop-down menu.

    2. 将连接字符串粘贴到“连接字符串”框中。Paste your connection string in the Connection string box. 要了解如何检索主要连接字符串,请参阅获取连接字符串For how to retrieve the primary connection string, see Get the connection string.

    3. 输入帐户标签,然后选择“下一步”以查看摘要 。Enter an Account label , and then select Next to check the summary.

    4. 选择“连接”来连接 Azure Cosmos DB 帐户。Select Connect to connect the Azure Cosmos DB account.

      “连接到 Cosmos DB”窗口的屏幕截图,其中显示 API 下拉菜单、“连接字符串”框和“帐户标签”框。

使用本地模拟器连接到 Azure Cosmos DBUse a local emulator to connect to Azure Cosmos DB

按照以下步骤,通过模拟器连接到 Azure Cosmos DB。Use the following steps to connect to an Azure Cosmos DB with an emulator. 此方法仅支持 SQL 帐户。This method only supports SQL accounts.

  1. 安装 Cosmos DB 模拟器,然后将其打开。Install Cosmos DB Emulator, and then open it. 要了解如何安装模拟器,请参阅 Cosmos DB 模拟器For how to install the emulator, see Cosmos DB Emulator.

  2. 在左侧树中找到“本地和附加”,右键单击“Cosmos DB 帐户”,然后选择“连接到 Cosmos DB 模拟器” 。Find Local and Attached in the left tree, right-click Cosmos DB Accounts , and then select Connect to Cosmos DB Emulator .

    显示右键单击后显示的菜单的屏幕截图,其中突出显示了“连接到 Azure Cosmos DB 模拟器”。

  3. 在“连接到 Cosmos DB”窗口中:In the Connect to Cosmos DB window:

    1. 将连接字符串粘贴到“连接字符串”框中。Paste your connection string in the Connection string box. 有关检索主连接字符串的信息,请参阅获取连接字符串For information on retrieving the primary connection string, see Get the connection string.

    2. 输入帐户标签,然后选择“下一步”以查看摘要 。Enter an Account label , and then select Next to check the summary.

    3. 选择“连接”来连接 Azure Cosmos DB 帐户。Select Connect to connect the Azure Cosmos DB account.

      “连接到 Cosmos DB”窗口的屏幕截图,其中显示“连接字符串”框和“帐户标签”框。

Azure Cosmos DB 资源管理Azure Cosmos DB resource management

执行以下操作来管理 Azure Cosmos DB 帐户:Use the following operations to manage an Azure Cosmos DB account:

  • 在 Azure 门户中打开该帐户。Open the account in the Azure portal.
  • 将资源添加到“快速访问”列表。Add the resource to the Quick Access list.
  • 搜索和刷新资源。Search and refresh resources.
  • 创建和删除数据库。Create and delete databases.
  • 创建和删除集合。Create and delete collections.
  • 创建、编辑、删除和筛选文档。Create, edit, delete, and filter documents.
  • 管理存储过程、触发器和用户定义的函数。Manage stored procedures, triggers, and user-defined functions.

快速访问任务Quick access tasks

可右键单击“资源管理器”窗格上的订阅,执行多项快速操作任务,例如:You can right-click a subscription on the Explorer pane to perform many quick action tasks, for example:

  • 右键单击 Azure Cosmos DB 帐户或数据库,然后选择“在门户中打开”,通过浏览器在 Azure 门户上管理资源。Right-click an Azure Cosmos DB account or database, and then select Open in Portal to manage the resource in the browser on the Azure portal.

    显示右键单击后显示的菜单的屏幕截图,其中突出显示了“在门户中打开”。

  • 右键单击 Azure Cosmos DB 帐户、数据库或集合,然后选择“添加到快速访问”,将其添加到“快速访问”菜单。Right-click an Azure Cosmos DB account, database, or collection, and then select Add to Quick Access to add it to the Quick Access menu.

  • 选择“从此处搜索”,启用所选路径下的关键字搜索。Select Search from Here to enable keyword search under the selected path.

    突出显示搜索框的屏幕截图。

数据库和集合管理Database and collection management

创建数据库Create a database

  1. 右键单击 Azure Cosmos DB 帐户,然后选择“创建数据库”。Right-click the Azure Cosmos DB account, and then select Create Database .

    显示右键单击后显示的菜单的屏幕截图,其中突出显示了“创建数据库”。

  2. 输入数据库名称,然后按 Enter 完成操作。Enter the database name, and then press Enter to complete.

删除数据库Delete a database

  1. 右键单击数据库,然后选择“删除数据库”。Right-click the database, and then select Delete Database .

    显示右键单击后显示的菜单的屏幕截图,其中突出显示了“删除数据库”。

  2. 在弹出窗口中选择“是”。Select Yes in the pop-up window. 数据库节点会删除,并且 Azure Cosmos DB 帐户会自动刷新。The database node is deleted, and the Azure Cosmos DB account refreshes automatically.

    确认窗口的屏幕截图,其中突出显示了“是”按钮。

创建集合Create a collection

  1. 右键单击数据库,然后选择“创建集合”。Right-click your database, and then select Create Collection .

    显示右键单击后显示的菜单的屏幕截图,其中突出显示了“创建集合”。

  2. 在“创建集合”窗口中,输入所请求的信息,例如集合 ID 和存储容量等 。In the Create Collection window, enter the requested information, like Collection ID and Storage capacity , and so on. 选择“确定”,以完成操作。Select OK to finish.

    “创建集合”窗口的屏幕截图,其中显示“集合 ID”框和“存储容量”按钮。

  3. 选择“无限制”,以便可指定分区键,然后选择“确定”来完成操作 。Select Unlimited so you can specify a partition key, then select OK to finish.

    备注

    如果在创建集合时使用了分区键,则创建完成后,无法更改集合上的分区键值。If a partition key is used when you create a collection, once creation is completed, you can't change the partition key value on the collection.

    “创建集合”窗口的屏幕截图,其中显示为“存储容量”选择了“无限制”,并突出显示了“分区键”框。

删除集合Delete a collection

  • 右键单击集合,选择“删除集合”,然后在弹出窗口中选择“是”。Right-click the collection, select Delete Collection , and then select Yes in the pop-up window.

    集合节点会删除,并且数据库会自动刷新。The collection node is deleted, and the database refreshes automatically.

    显示右键单击后显示的菜单的屏幕截图,其中突出显示了“删除集合”。

文档管理Document management

创建和修改文档Create and modify documents

  • 在左侧窗格中打开“文档”,选择“新建文档”,在右侧窗格中编辑内容,然后选择“保存” 。Open Documents on the left pane, select New Document , edit the contents on the right pane, and then select Save .

  • 还可以更新现有文档,然后选择“保存”。You can also update an existing document, and then select Save . 若要放弃更改,请选择“放弃”。To discard changes, select Discard .

    左侧窗格中突出显示了“文档”的屏幕截图。在右侧窗格中,突出显示了“新建文档”、“保存”和“放弃”。

删除文档Delete a document

  • 选择“删除”按钮,删除所选文档。Select the Delete button to delete the selected document.

查询文档Query for documents

  • 若要编辑文档筛选器,请输入 SQL 查询,然后选择“应用”。To edit the document filter, enter a SQL query, and then select Apply .

    右侧窗格的屏幕截图,其中突出显示了“筛选”和“应用”按钮、ID 号和查询框。

图形管理Graph management

创建和修改顶点Create and modify a vertex

  • 若要创建新顶点,请从左侧窗格中打开“图形”,选择“新建顶点”,编辑内容,然后选择“确定” 。To create a new vertex, open Graph from the left pane, select New Vertex , edit the contents, and then select OK .

  • 若要修改现有顶点,请在右侧窗格中选择笔图标。To modify an existing vertex, select the pen icon on the right pane.

    一张屏幕截图,其中左侧窗格中选择了“图形”,显示了“新建顶点”,且右侧窗格中突出显示了笔图标。

创建图形Delete a graph

  • 若要删除某个顶点,请选择顶点名称旁边的回收站图标。To delete a vertex, select the recycle bin icon beside the vertex name.

筛选图形Filter for graph

  • 若要编辑图形筛选器,请输入 gremlin 查询,然后选择“应用筛选器”。To edit the graph filter, enter a gremlin query, and then select Apply Filter .

    一张屏幕截图,其中左侧窗格中选择了“图形”,显示了“应用筛选器”,且右侧窗格中突出显示了查询框。

表管理Table management

创建和修改表Create and modify a table

  • 若要创建新表:To create a new table:

    1. 在左侧窗格中,打开“实体”,然后选择“添加” 。On the left pane, open Entities , and then select Add .

    2. 在“添加实体”对话框中,编辑内容。In the Add Entity dialog box, edit the content.

    3. 选择“添加属性”按钮以添加属性。Select the Add Property button to add a property.

    4. 选择“插入” 。Select Insert .

      一张屏幕截图,其中左侧窗格中突出显示了“实体”,右侧窗格中突出显示了“添加”、“编辑”、“添加属性”和“插入”。

  • 若要修改表,请选择“编辑”,修改内容,然后选择“更新” 。To modify a table, select Edit , modify the content, and then select Update .

导入和导出表Import and export table

  • 若要导入,请选择“导入”按钮并选择现有的表。To import, select the Import button, and then choose an existing table.

  • 若要导出,请选择“导出”按钮并选择一个目标。To export, select the Export button, and then choose a destination.

    右侧窗格中突出显示了“导入”和“导出”按钮的屏幕截图。

删除实体Delete entities

  • 选择实体,然后选择“删除”按钮。Select the entities, and then select the Delete button.

    一张屏幕截图,其中右侧窗格中突出显示了“删除”按钮,还有一个突出显示了“是”选项的确认弹出窗口。

查询表Query a table

  • 选择“查询”按钮,输入查询条件,然后选择“执行查询”按钮 。Select the Query button, input a query condition, and then select the Execute Query button. 若要关闭查询窗格,请选择“关闭查询”按钮。To close the query pane, select the Close Query button.

    右侧窗格的屏幕截图,其中显示了“执行查询”按钮并突出显示了“关闭查询”按钮。

管理存储过程、触发器和 UDFManage stored procedures, triggers, and UDFs

  • 若要创建存储过程:To create a stored procedure:

    1. 在左侧树中,右键单击“存储过程”,然后选择“创建存储过程” 。In the left tree, right-click Stored Procedures , and then select Create Stored Procedure .

      左侧窗格的屏幕截图,其中显示右键单击后显示的菜单并突出显示了“创建存储过程”。

    2. 在左侧输入名称,在右侧窗格中输入存储过程脚本,然后选择“创建”。Enter a name in the left, enter the stored procedure scripts on the right pane, and then select Create .

  • 若要编辑现有存储过程,请双击该过程,进行更新,然后选择“更新”进行保存。To edit an existing stored procedure, double-click the procedure, make the update, and then select Update to save. 也可选择“放弃”来取消更改。You can also select Discard to cancel the change.

  • 用于触发器和 UDF 的操作与存储过程类似 。The operations for Triggers and UDF are similar to Stored Procedures .

故障排除Troubleshooting

下面是针对在存储资源管理器中使用 Azure Cosmos DB 时出现的常见问题的解决方案。The following are solutions to common issues that arise when you use Azure Cosmos DB in Storage Explorer.

登录问题Sign in issues

首先,重启应用程序,看看能否解决问题。First, restart your application to see if that fixes the problem. 如果问题仍然存在,请继续进行故障排除。If the problem persists, continue troubleshooting.

证书链中的自签名证书Self-signed certificate in certificate chain

出现此错误有多个原因,最常见的两个原因是:There are a few reasons you might be seeing this error, the two most common ones are:

  • 你在使用透明代理。You're behind a transparent proxy . 有人(例如你的 IT 部门)会截获 HTTPS 流量,对其进行解密,然后使用自签名证书对其进行加密。Someone, like your IT department, intercepts HTTPS traffic, decrypts it, and then encrypts it by using a self-signed certificate.

  • 你正在运行软件,例如防病毒软件。You're running software, such as antivirus software. 软件将自签名的 TLS/SSL 证书注入收到的 HTTPS 消息中。The software injects a self-signed TLS/SSL certificate into the HTTPS messages you receive.

当存储资源管理器找到自签名证书时,它不知道自己收到的 HTTPS 消息是否遭到篡改。When Storage Explorer finds a self-signed certificate, it doesn't know if the HTTPS message it receives is tampered with. 如果拥有自签名证书的副本,则可命令存储资源管理器信任它。If you have a copy of the self-signed certificate, you can tell Storage Explorer to trust it. 如果不确定谁注入了证书,可按照以下步骤操作,尝试将其找出来:If you're unsure of who injected the certificate, then you can follow these steps to try to find out:

  1. 安装 OpenSSL:Install OpenSSL:

    • Windows:任意轻量版本均可。Windows: Any of the light versions are OK.
    • macOS 和 Linux:应包含在操作系统中。macOS and Linux: Should be included with your operating system.
  2. 运行 OpenSSL:Run OpenSSL:

    • Windows:转到安装目录,转到“/bin/”,然后双击“openssl.exe” 。Windows: Go to the install directory, then /bin/ , then double-click openssl.exe .
    • Mac 和 Linux:从终端执行 openssl。Mac and Linux: Execute openssl from a terminal.
  3. 执行 s_client -showcerts -connect microsoft.com:443Execute s_client -showcerts -connect microsoft.com:443.

  4. 查找自签名证书。Look for self-signed certificates. 如果不确定哪个是自签名证书,请查找使用者(“s:”)与证书颁发者(“i:”)相同的任意位置。If you're unsure, which are self-signed, then look for anywhere that the subject ("s:") and issuer ("i:") are the same.

  5. 如果找到任何自签名证书,请将每个证书中从“-----BEGIN CERTIFICATE-----”(含)到“-----END CERTIFICATE-----”(含)的部分复制粘贴到新的 .CER 文件。 。If you find any self-signed certificates, copy and paste everything from and including -----BEGIN CERTIFICATE----- to -----END CERTIFICATE----- to a new .CER file for each one.

  6. 打开存储资源管理器,然后转到“编辑” > “SSL 证书” > “导入证书” 。Open Storage Explorer, and then go to Edit > SSL Certificates > Import Certificates . 使用文件选取器查找、选择并打开所创建的 .CER 文件。Use the file picker to find, select, and then open the .CER files you created.

如果找不到任何自签名证书,则可发送反馈以获取更多帮助。If you don't find any self-signed certificates, you can send feedback for more help.

无法检索订阅Unable to retrieve subscriptions

如果登录后无法检索到订阅,请尝试以下建议:If you're unable to retrieve your subscriptions after you sign in, try these suggestions:

  • 验证你的帐户是否可访问订阅。Verify that your account has access to the subscriptions. 为此,请登录 Azure 门户To do this, sign in to the Azure portal.

  • 确保登录到正确的环境:Make sure you signed in to the correct environment:

  • 如果使用代理,请确保已正确配置存储资源管理器代理。If you're behind a proxy, make sure that the Storage Explorer proxy is properly configured.

  • 删除帐户,然后重新添加它。Remove the account, and then add it again.

  • 从主目录(例如:C:\Users\ContosoUser)中删除以下文件,然后重新添加帐户:Delete the following files from your home directory (such as: C:\Users\ContosoUser), and then add the account again:

    • .adalcache.adalcache
    • .devaccounts.devaccounts
    • .extaccounts.extaccounts
  • 按 F12 键打开开发人员控制台。Press the F12 key to open the developer console. 登录时,请在控制台中查看是否出现任何错误消息。Watch the console for any error messages when you sign in.

    开发人员工具控制台的屏幕截图,其中突出显示了“控制台”。

无法查看身份验证页Unable to see the authentication page

如果无法看到身份验证页面:If you're unable to see the authentication page:

  • 根据连接速度,可能需要一段时间才能加载登录页面。Depending on the speed of your connection, it might take a while for the sign-in page to load. 请等待至少一分钟,然后再关闭身份验证对话框。Wait at least one minute before you close the authentication dialog box.
  • 如果使用代理,请确保已正确配置存储资源管理器代理。If you're behind a proxy, make sure that the Storage Explorer proxy is properly configured.
  • 在开发人员工具控制台 (F12) 上,观察响应,查看能否找到有关身份验证为何不起作用的任何线索。On the developer tools console (F12), watch the responses to see if you can find any clue for why authentication isn't working.

无法删除帐户Can't remove an account

如果无法删除帐户,或者重新验证链接不起作用,请执行以下操作:If you're unable to remove an account, or if the reauthenticate link doesn't do anything:

  • 从主目录中删除以下文件,然后再次添加帐户:Delete the following files from your home directory, and then add the account again:

    • .adalcache.adalcache
    • .devaccounts.devaccounts
    • .extaccounts.extaccounts
  • 若要删除附加了 SAS 的存储资源,请删除:If you want to remove SAS attached Storage resources, delete:

    • %AppData%/StorageExplorer 文件夹(对于 Windows)%AppData%/StorageExplorer folder for Windows
    • /Users/<your_name>/Library/Application SUpport/StorageExplorer(对于 macOS)/Users/<your_name>/Library/Application SUpport/StorageExplorer for macOS
    • ~/.config/StorageExplorer(对于 Linux)~/.config/StorageExplorer for Linux

    备注

    如果删除这些文件,则必须重新输入所有凭据。If you delete these files, you must reenter all your credentials .

HTTP/HTTPS 代理问题HTTP/HTTPS proxy issue

在 ASE 中配置 HTTP/HTTPS 代理时,无法在左侧树中列出 Azure Cosmos DB 节点。You can't list Azure Cosmos DB nodes in the left tree when you configure an HTTP/HTTPS proxy in ASE. 可在 Azure 门户中使用 Azure Cosmos DB 数据资源管理器作为解决方法。You can use Azure Cosmos DB data explorer in the Azure portal as a work-around.

“本地和附加”节点下的“开发”节点问题"Development" node under "Local and Attached" node issue

在左侧树中选择“本地和附加”节点下的“开发”节点后没有响应 。There's no response after you select the Development node under the Local and Attached node in the left tree. 此行为是预期的行为。The behavior is expected.

显示选定的“开发”节点的屏幕截图。

在“本地和附加”节点错误中附加 Azure Cosmos DB 帐户Attach an Azure Cosmos DB account in the Local and Attached node error

如果在“本地和附加”节点中附加 Azure Cosmos DB 帐户后看到以下错误,请确保使用正确的连接字符串。If you see the following error after you attach an Azure Cosmos DB account in Local and Attached node, then make sure you're using the correct connection string.

“无法检索子资源”错误弹出窗口的屏幕截图,其中指示 getaddrinfo ENOTFOUND。

展开 Azure Cosmos DB 节点错误Expand Azure Cosmos DB node error

尝试在左侧树中展开节点时,可能会出现以下错误。You might see the following error when you try to expand nodes in the left tree.

“无法检索子资源”错误弹出窗口的屏幕截图,其中指示无法连接到该 Cosmos DB 帐户。

请尝试以下建议:Try these suggestions:

  • 检查 Azure Cosmos DB 帐户是否正在预配。Check if the Azure Cosmos DB account is in provision progress. 成功创建帐户后,请重试。Try again when the account is being created successfully.
  • 如果该帐户位于“快速访问”或“本地和附加”节点下,请检查该帐户是否已删除 。If the account is under the Quick Access or Local and Attached nodes, check if the account is deleted. 如果是,则需要手动删除该节点。If so, you need to manually remove the node.

后续步骤Next steps