Bagikan melalui


Pustaka klien Azure Atlas untuk JavaScript - versi 1.0.0

Paket ini berisi SDK isomorfik (berjalan di Node.js dan di browser) untuk klien Azure Atlas.

Key links:

Getting started

Lingkungan yang didukung saat ini

See our support policy for more details.

Prerequisites

Pasang paket @azure/arm-mongodbatlas

Instal pustaka klien Azure Atlas untuk JavaScript dengan npm:

npm install @azure/arm-mongodbatlas

Membuat dan mengautentikasi AtlasClient

Untuk membuat objek klien untuk mengakses Azure Atlas API, Anda memerlukan endpoint sumber daya Azure Atlas dan .credential Klien Azure Atlas dapat menggunakan kredensial Azure Active Directory untuk mengautentikasi. 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

Anda juga perlu mendaftarkan aplikasi AAD baru dan memberikan akses ke Azure Atlas dengan menetapkan peran yang sesuai ke perwakilan layanan Anda (catatan: peran seperti tidak "Owner" akan memberikan izin yang diperlukan).

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

Dengan menggunakan lingkungan Node.js dan seperti Node, Anda dapat menggunakan kelas DefaultAzureCredential untuk mengautentikasi klien.

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

Untuk lingkungan browser, gunakan InteractiveBrowserCredential dari paket @azure/identity untuk mengautentikasi.

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

Untuk menggunakan pustaka klien ini di browser, pertama-tama Anda perlu menggunakan bunder. For details on how to do this, please refer to our bundling documentation.

Key concepts

AtlasClient

AtlasClient adalah antarmuka utama untuk pengembang yang menggunakan pustaka klien Azure Atlas. Jelajahi metode pada objek klien ini untuk memahami berbagai fitur layanan Azure Atlas yang dapat Anda akses.

Troubleshooting

Logging

Mengaktifkan pengelogan dapat membantu menemukan informasi yang berguna tentang kegagalan. Untuk melihat log permintaan dan respons HTTP, atur variabel lingkungan AZURE_LOG_LEVEL ke info. Atau, pengelogan dapat diaktifkan saat runtime dengan memanggil setLogLevel di @azure/logger:

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

setLogLevel("info");

Untuk instruksi lebih rinci tentang cara mengaktifkan log, Anda dapat melihat dokumen paket @azure/logger.

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.