Dela via


Azure Atlas-klientbibliotek för JavaScript – version 1.0.0

Det här paketet innehåller en isomorfisk SDK (körs både i Node.js och i webbläsare) för Azure Atlas-klienten.

Key links:

Getting started

Miljöer som stöds för närvarande

See our support policy for more details.

Prerequisites

Installera @azure/arm-mongodbatlas-paketet

Installera Azure Atlas-klientbiblioteket för JavaScript med npm:

npm install @azure/arm-mongodbatlas

Skapa och autentisera en AtlasClient

Om du vill skapa ett klientobjekt för att få åtkomst till Azure Atlas-API:et behöver du för endpoint din Azure Atlas-resurs och en credential. Azure Atlas-klienten kan använda Azure Active Directory-autentiseringsuppgifter för att autentisera. 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

Du måste också registrera ett nytt AAD-program och bevilja åtkomst till Azure Atlas genom att tilldela lämplig roll till tjänstens huvudnamn (observera att roller som inte beviljar de behörigheter som "Owner" krävs).

For more information about how to create an Azure AD Application check out this guide.

Med hjälp av Node.js- och Node-liknande miljöer kan du använda klassen DefaultAzureCredential för att autentisera klienten.

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);

För webbläsarmiljöer använder du InteractiveBrowserCredential från @azure/identity-paketet för att autentisera.

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

Om du vill använda det här klientbiblioteket i webbläsaren måste du först använda en bundler. For details on how to do this, please refer to our bundling documentation.

Key concepts

AtlasClient

AtlasClient är det primära gränssnittet för utvecklare som använder Azure Atlas-klientbiblioteket. Utforska metoderna för det här klientobjektet för att förstå de olika funktionerna i Azure Atlas-tjänsten som du kan komma åt.

Troubleshooting

Logging

Aktivering av loggning kan hjälpa dig att hitta användbar information om fel. Om du vill se en logg med HTTP-begäranden och svar anger du AZURE_LOG_LEVEL miljövariabeln till info. Du kan också aktivera loggning vid körning genom att anropa setLogLevel i @azure/logger:

import { setLogLevel } from "@azure/logger";

setLogLevel("info");

Mer detaljerade anvisningar om hur du aktiverar loggar finns i dokument för @azure/logger-paket.

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.