Share via


使用 Studio 3T 連線至 Azure Cosmos DB 帳戶

適用於: MongoDB

若要使用 Studio 3T 連線到適用於 MongoDB 的 Azure Cosmos DB API,您必須:

在 Studio 3T 中建立連線

若要將 Azure Cosmos DB 帳戶新增至 Studio 3T 連線管理員,請使用下列步驟:

  1. 使用將 MongoDB 應用程式連線到 Azure Cosmos DB 一文中的指示,針對適用於 MongoDB 的 Azure Cosmos DB API 帳戶擷取連線資訊。

    Screenshot of the connection string page

  2. 按一下 [連接] 以開啟 [連接管理員],然後按一下 [新增連線]

    Screenshot of the Studio 3T connection manager that highlights the New Connection button.

  3. 在 [新增連線] 視窗中,在 [伺服器] 索引標籤上輸入 Azure Cosmos DB 帳戶的主機 (FQDN) 和連接埠。

    Screenshot of the Studio 3T connection manager server tab

  4. 在 [新增連線] 視窗中,請在 [驗證] 索引標籤上選擇驗證模式 [基本 (MONGODB-CR 或 SCRAM-SHA-1)],並輸入使用者名稱和密碼。 接受預設的驗證資料庫 (管理員),或提供您自己的值。

    Screenshot of the Studio 3T connection manager authentication tab

  5. 在 [新增連接] 視窗的 [SSL] 索引標籤上,勾選 [使用 SSL 通訊協定連接] 核取方塊和 [接受自我簽署的 SSL 憑證] 選項按鈕。

    Screenshot of the Studio 3T connection manager SSL tab

  6. 按一下 [測試連接] 按鈕以驗證連接資訊,按一下 [確定] 以返回 [新增連線] 視窗,然後按一下 [儲存]

    Screenshot of the Studio 3T test connection window

使用 Studio 3T 建立資料庫、集合和文件

若要使用 Studio 3T 建立資料庫、集合和文件,請執行下列步驟:

  1. 在 [連接管理員] 中,反白顯示連接,然後按一下 [連接]

    Screenshot of the Studio 3T connection manager

  2. 以滑鼠右鍵按一下主機,然後選擇 [新增資料庫]。 提供資料庫名稱,然後按一下 [確定]

    Screenshot of the Studio 3T Add Database option

  3. 以滑鼠右鍵按一下資料庫,然後選擇 [新增集合]。 提供集合名稱,然後按一下 [建立]

    Screenshot of the Studio 3T Add Collection option

  4. 按一下 [集合] 功能表項目,然後按一下 [新增文件]

    Screenshot of the Studio 3T Add Document menu item

  5. 在 [新增文件] 對話方塊中,貼上下列項目,然後按一下 [新增文件]

    {
        "_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. 新增其他文件,這次使用下列內容:

    {
        "_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. 執行範例查詢。 例如,搜尋姓氏 'Andersen' 的家族,並傳回父母和州欄位。

    Screenshot of Mongo Chef query results

下一步