此包包含適用於 Azure Atlas 用戶端的同構 SDK(在 Node.js 和瀏覽器中運行)。
Key links:
Getting started
目前支援的環境
- LTS 版本的 Node.js
- 最新版的 Safari、Chrome、Edge 和 Firefox。
See our support policy for more details.
Prerequisites
安裝 @azure/arm-mongodbatlas 套件
使用以下命令 npm安裝適用於 JavaScript 的 Azure Atlas 用戶端庫:
npm install @azure/arm-mongodbatlas
建立和驗證 AtlasClient
要建立客戶端物件以訪問 Azure Atlas API,您需要 endpoint Azure Atlas 資源的 credential. Azure Atlas 用戶端可以使用 Azure Active Directory 憑據進行身份驗證。
You can find the endpoint for your Azure Atlas resource in the Azure Portal.
You can authenticate with Azure Active Directory using a credential from the @azure/identity library or an existing AAD Token.
To use the DefaultAzureCredential provider shown below, or other credential providers provided with the Azure SDK, please install the @azure/identity package:
npm install @azure/identity
您還需要 註冊一個新的 AAD 應用程式,並通過 為您的服務主體分配合適的角色來授予對 Azure Atlas 的訪問許可權(注意:此類 "Owner" 角色不會授予必要的許可權)。
For more information about how to create an Azure AD Application check out this guide.
使用 Node.js 和類似節點的環境,您可以使用 DefaultAzureCredential 類別來驗證用戶端。
import { AtlasClient } from "@azure/arm-mongodbatlas";
import { DefaultAzureCredential } from "@azure/identity";
const subscriptionId = "00000000-0000-0000-0000-000000000000";
const client = new AtlasClient(new DefaultAzureCredential(), subscriptionId);
針對瀏覽器環境,請使用來自 InteractiveBrowserCredential 套件的 @azure/identity 進行驗證。
import { InteractiveBrowserCredential } from "@azure/identity";
import { AtlasClient } from "@azure/arm-mongodbatlas";
const credential = new InteractiveBrowserCredential({
tenantId: "<YOUR_TENANT_ID>",
clientId: "<YOUR_CLIENT_ID>",
});
const subscriptionId = "00000000-0000-0000-0000-000000000000";
const client = new AtlasClient(credential, subscriptionId);
JavaScript Bundle
若要在瀏覽器中使用此用戶端連結庫,您必須先使用配套程式。 For details on how to do this, please refer to our bundling documentation.
Key concepts
AtlasClient
AtlasClient 是使用 Azure Atlas 用戶端庫的開發人員的主要介面。 探索此客戶端物件上的方法,以瞭解可以訪問的 Azure Atlas 服務的不同功能。
Troubleshooting
Logging
啟用記錄可能有助於找出有關失敗的實用資訊。 若要查看 HTTP 要求和回應的記錄,請將 AZURE_LOG_LEVEL 環境變數設定為 info。 或者,您可以在運行時間啟用記錄,方法是在 setLogLevel中呼叫 @azure/logger:
import { setLogLevel } from "@azure/logger";
setLogLevel("info");
如需如何啟用記錄的詳細指示,請參閱
Next steps
Please take a look at the samples directory for detailed examples on how to use this library.
Contributing
If you'd like to contribute to this library, please read the contributing guide to learn more about how to build and test the code.