使用 Studio 3T 连接到 Azure Cosmos 帐户Connect to an Azure Cosmos account using Studio 3T

若要使用 Studio 3T 连接到 Azure Cosmos DB 的 API for MongoDB,必须执行以下操作:To connect to an Azure Cosmos DB's API for MongoDB using Studio 3T, you must:

在 Studio 3T 中创建连接Create the connection in Studio 3T

若要将 Azure Cosmos 帐户添加到 Studio 3T 连接管理器,请执行以下步骤:To add your Azure Cosmos account to the Studio 3T connection manager, use the following steps:

  1. 按照将 MongoDB 应用程序连接到 Azure Cosmos DB 一文中的说明,检索 Azure Cosmos DB 的 API for MongoDB 帐户的连接信息。Retrieve the connection information for your Azure Cosmos DB's API for MongoDB account using the instructions in the Connect a MongoDB application to Azure Cosmos DB article.

    连接字符串页的屏幕截图

  2. 单击“连接” 以打开“连接管理器”,并单击“新建连接” Click Connect to open the Connection Manager, then click New Connection

    Studio 3T 连接管理器的屏幕截图

  3. 在“新建连接”窗口中的“服务器”选项卡上,输入 Azure Cosmos 帐户的主机 (FQDN) 和端口 。In the New Connection window, on the Server tab, enter the HOST (FQDN) of the Azure Cosmos account and the PORT.

    Studio 3T 连接管理器服务器选项卡的屏幕截图

  4. 在“新建连接” 窗口中的“身份验证” 选项卡上,选择“基本(MONGODB-CR 或 SCARM-SHA-1)” 身份验证模式,并输入用户名和密码。In the New Connection window, on the Authentication tab, choose Authentication Mode Basic (MONGODB-CR or SCARM-SHA-1) and enter the USERNAME and PASSWORD. 接受默认的身份验证数据库(管理员),或提供自己的值。Accept the default authentication db (admin) or provide your own value.

    Studio 3T 连接管理器身份验证选项卡的屏幕截图

  5. 在“新建连接” 窗口的“SSL” 选项卡上,选中“使用 SSL 协议进行连接” 复选框和“接受服务器自签名 SSL 证书” 单选按钮。In the New Connection window, on the SSL tab, check the Use SSL protocol to connect check box and the Accept server self-signed SSL certificates radio button.

    Studio 3T 连接管理器 SSL 选项卡的屏幕截图

  6. 单击“测试连接” 按钮以验证连接信息,单击“确定” 以返回到“新建连接”窗口,并单击“保存” 。Click the Test Connection button to validate the connection information, click OK to return to the New Connection window, and then click Save.

    Studio 3T 测试连接窗口的屏幕截图

使用 Studio 3T 创建数据库、集合和文档Use Studio 3T to create a database, collection, and documents

若要使用 Studio 3T 创建数据库、集合和文档,请执行以下步骤:To create a database, collection, and documents using Studio 3T, perform the following steps:

  1. 在“连接管理器” 中突出显示连接,并单击“连接” 。In Connection Manager, highlight the connection and click Connect.

    Studio 3T 连接管理器的屏幕截图

  2. 右键单击主机,并选择“添加数据库” 。Right-click the host and choose Add Database. 提供数据库名称,并单击“确定” 。Provide a database name and click OK.

    Studio 3T“添加数据库”选项的屏幕截图

  3. 右键单击数据库,并选择“添加集合” 。Right-click the database and choose Add Collection. 提供集合名称,并单击“创建” 。Provide a collection name and click Create.

    Studio 3T“添加集合”选项的屏幕截图

  4. 单击“集合” 菜单项,并单击“添加文档” 。Click the Collection menu item, then click Add Document.

    Studio 3T“添加文档”菜单项的屏幕截图

  5. 在“添加文档”对话框中粘贴以下内容,并单击“添加文档” 。In the Add Document dialog, paste the following and then click Add Document.

     {
         "_id": "AndersenFamily",
         "lastName": "Andersen",
         "parents": [
                { "firstName": "Thomas" },
                { "firstName": "Mary Kay"}
         ],
         "children": [
            {
                "firstName": "Henriette Thaulow", "gender": "female", "grade": 5,
                "pets": [{ "givenName": "Fluffy" }]
            }
         ],
         "address": { "state": "WA", "county": "King", "city": "seattle" },
         "isRegistered": true
     }
    
  6. 添加另一个文档,但这次使用以下内容:Add another document, this time with the following content:

     {
         "_id": "WakefieldFamily",
         "parents": [
             { "familyName": "Wakefield", "givenName": "Robin" },
             { "familyName": "Miller", "givenName": "Ben" }
         ],
         "children": [
             {
                 "familyName": "Merriam",
                  "givenName": "Jesse",
                 "gender": "female", "grade": 1,
                 "pets": [
                     { "givenName": "Goofy" },
                     { "givenName": "Shadow" }
                 ]
             },
             {
                 "familyName": "Miller",
                  "givenName": "Lisa",
                  "gender": "female",
                  "grade": 8 }
         ],
         "address": { "state": "NY", "county": "Manhattan", "city": "NY" },
         "isRegistered": false
     }
    
  7. 执行示例查询。Execute a sample query. 例如,搜索姓氏为“Andersen”的家庭,并返回父母和州/省字段。For example, search for families with the last name 'Andersen' and return the parents and state fields.

    Mongo Chef 查询结果的屏幕截图

后续步骤Next steps

  • 了解如何将 Robo 3T 与 Azure Cosmos DB 的用于 MongoDB 的 API 配合使用。Learn how to use Robo 3T with Azure Cosmos DB's API for MongoDB.
  • 通过 Azure Cosmos DB 的用于 MongoDB 的 API 来浏览 MongoDB 示例Explore MongoDB samples with Azure Cosmos DB's API for MongoDB.