Aracılığıyla paylaş


Container class

Kimliğe göre belirli bir kapsayıcıyı okuma, değiştirme veya silme işlemleri.

Yeni kapsayıcılar oluşturmak ve tüm kapsayıcıları okumak/sorgulamak için bkz. Kapsayıcılar; .containerskullanın.

Not: Tüm bu işlemler sabit bir bütçeye göre çağrı yapar. Sisteminizi, bu çağrıların uygulamanızla birlikte alt satır olarak ölçeklendirilmesi için tasarlamanız gerekir. Örneğin, kapsayıcının mevcut olduğundan emin olmak için her container(id).read() çağrısından önce item.read() çağırmayın; uygulama başlatılırken bunu bir kez yapın.

Özellikler

conflicts

Verilen kapsayıcı için okuma ve sorgulama çakışmaları için işlemler.

Belirli bir çakışmayı okumak veya silmek için .conflict(id)kullanın.

database
id
items

Yeni öğe oluşturma ve tüm öğeleri okuma/sorgulama işlemleri

Var olan bir öğeyi okumak, değiştirmek veya silmek için .item(id)kullanın.

Örnek

Yeni öğe oluşturma

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const { resource: createdItem } = await container.items.create({
  id: "<item id>",
  properties: {},
});
scripts

Saklı Yordamlar, Tetikleyiciler ve Kullanıcı Tanımlı İşlevler için tüm işlemler

url

Kaynağa bir başvuru URL'si döndürür. İzinler'de bağlantı için kullanılır.

Yöntemler

conflict(string, PartitionKey)

Kimliğe göre belirli bir Çakışma okumak, değiştirmek veya silmek için kullanılır.

Yeni çakışmalar oluşturmak veya tüm çakışmaları sorgulamak/okumak için .conflicts kullanın.

Örnek

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
const container = database.container("Test Container");

const { resource: conflict } = await container.conflict("<conflict-id>").read();
delete(RequestOptions)

Kapsayıcıyı silme

Örnek

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

await client.database("<db id>").container("<container id>").delete();
deleteAllItemsForPartitionKey(PartitionKey, RequestOptions)

Sağlanan bölüm anahtarı değeri için kapsayıcıya ait tüm belgeleri silme

Örnek

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({
  id: "Test Container",
  partitionKey: {
    paths: ["/state"],
  },
});

const cities = [
  { id: "1", name: "Olympia", state: "WA", isCapitol: true },
  { id: "2", name: "Redmond", state: "WA", isCapitol: false },
  { id: "3", name: "Olympia", state: "IL", isCapitol: false },
];
for (const city of cities) {
  await container.items.create(city);
}

await container.deleteAllItemsForPartitionKey("WA");
getFeedRanges()

Örnek

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const { resources: ranges } = await container.getFeedRanges();
getPartitionKeyDefinition()

Önce önbelleğine bakarak bölüm anahtarı tanımını alır, aksi takdirde koleksiyonu okuyarak.

getQueryPlan(string | SqlQuerySpec)
initializeEncryption()

Kapsayıcı için şifrelemeyle ilgili önbellekleri ısıtır.

Örnek

import { ClientSecretCredential } from "@azure/identity";
import {
  AzureKeyVaultEncryptionKeyResolver,
  CosmosClient,
  EncryptionType,
  EncryptionAlgorithm,
  ClientEncryptionIncludedPath,
  ClientEncryptionPolicy,
} from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const credentials = new ClientSecretCredential("<tenant-id>", "<client-id>", "<app-secret>");
const keyResolver = new AzureKeyVaultEncryptionKeyResolver(credentials);
const client = new CosmosClient({
  endpoint,
  key,
  clientEncryptionOptions: {
    keyEncryptionKeyResolver: keyResolver,
  },
});
const { database } = await client.databases.createIfNotExists({ id: "<db id>" });

const paths = ["/path1", "/path2", "/path3"].map(
  (path) =>
    ({
      path: path,
      clientEncryptionKeyId: "< cek - id >",
      encryptionType: EncryptionType.DETERMINISTIC,
      encryptionAlgorithm: EncryptionAlgorithm.AEAD_AES_256_CBC_HMAC_SHA256,
    }) as ClientEncryptionIncludedPath,
);
const clientEncryptionPolicy: ClientEncryptionPolicy = {
  includedPaths: paths,
  policyFormatVersion: 2,
};
const containerDefinition = {
  id: "Test Container",
  partitionKey: {
    paths: ["/id"],
  },
  clientEncryptionPolicy: clientEncryptionPolicy,
};
const { container } = await database.containers.createIfNotExists(containerDefinition);

await container.initializeEncryption();
item(string, PartitionKey)

Kimliğe göre belirli bir Öğe okumak, değiştirmek veya silmek için kullanılır.

Yeni öğeler oluşturmak veya tüm öğeleri sorgulamak/okumak için .items kullanın.

Örnek

Bir öğeyi değiştirme

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const { body: replacedItem } = await container
  .item("<item id>", "<partition key value>")
  .replace({ id: "<item id>", title: "Updated post", authorID: 5 });
read(RequestOptions)

Kapsayıcının tanımını okuma

Örnek

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { resource: database } = await client.database("<db id>").container("<container id>").read();
readOffer(RequestOptions)

Kapsayıcıda teklif alır. Yoksa, tanımlanmamış bir OfferResponse döndürür.

Örnek

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { resource: offer } = await client
  .database("<db id>")
  .container("<container id>")
  .readOffer();
readPartitionKeyRanges(FeedOptions)

Kapsayıcı için bölüm anahtarı aralıklarını alır.

Örnek

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const { resources: ranges } = await container.readPartitionKeyRanges().fetchAll();
replace(ContainerDefinition, RequestOptions)

Kapsayıcının tanımını değiştirme

Örnek

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const containerDefinition = {
  id: "Test Container",
  partitionKey: {
    paths: ["/key1"],
  },
  throughput: 1000,
};
const { container } = await database.containers.createIfNotExists(containerDefinition);

containerDefinition.throughput = 400;
const { container: replacedContainer } = await container.replace(containerDefinition);

Özellik Ayrıntıları

conflicts

Verilen kapsayıcı için okuma ve sorgulama çakışmaları için işlemler.

Belirli bir çakışmayı okumak veya silmek için .conflict(id)kullanın.

Conflicts conflicts

Özellik Değeri

database

database: Database

Özellik Değeri

id

id: string

Özellik Değeri

string

items

Yeni öğe oluşturma ve tüm öğeleri okuma/sorgulama işlemleri

Var olan bir öğeyi okumak, değiştirmek veya silmek için .item(id)kullanın.

Örnek

Yeni öğe oluşturma

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const { resource: createdItem } = await container.items.create({
  id: "<item id>",
  properties: {},
});
Items items

Özellik Değeri

scripts

Saklı Yordamlar, Tetikleyiciler ve Kullanıcı Tanımlı İşlevler için tüm işlemler

Scripts scripts

Özellik Değeri

url

Kaynağa bir başvuru URL'si döndürür. İzinler'de bağlantı için kullanılır.

string url

Özellik Değeri

string

Yöntem Ayrıntıları

conflict(string, PartitionKey)

Kimliğe göre belirli bir Çakışma okumak, değiştirmek veya silmek için kullanılır.

Yeni çakışmalar oluşturmak veya tüm çakışmaları sorgulamak/okumak için .conflicts kullanın.

Örnek

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
const container = database.container("Test Container");

const { resource: conflict } = await container.conflict("<conflict-id>").read();
function conflict(id: string, partitionKey?: PartitionKey): Conflict

Parametreler

id

string

Çakışmakimliği.

partitionKey
PartitionKey

Döndürülenler

delete(RequestOptions)

Kapsayıcıyı silme

Örnek

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

await client.database("<db id>").container("<container id>").delete();
function delete(options?: RequestOptions): Promise<ContainerResponse>

Parametreler

options
RequestOptions

Döndürülenler

deleteAllItemsForPartitionKey(PartitionKey, RequestOptions)

Sağlanan bölüm anahtarı değeri için kapsayıcıya ait tüm belgeleri silme

Örnek

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({
  id: "Test Container",
  partitionKey: {
    paths: ["/state"],
  },
});

const cities = [
  { id: "1", name: "Olympia", state: "WA", isCapitol: true },
  { id: "2", name: "Redmond", state: "WA", isCapitol: false },
  { id: "3", name: "Olympia", state: "IL", isCapitol: false },
];
for (const city of cities) {
  await container.items.create(city);
}

await container.deleteAllItemsForPartitionKey("WA");
function deleteAllItemsForPartitionKey(partitionKey: PartitionKey, options?: RequestOptions): Promise<ContainerResponse>

Parametreler

partitionKey
PartitionKey

Silinecek öğelerin bölüm anahtarı değeri

options
RequestOptions

Döndürülenler

getFeedRanges()

Örnek

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const { resources: ranges } = await container.getFeedRanges();
function getFeedRanges(): Promise<readonly FeedRange[]>

Döndürülenler

Promise<readonly FeedRange[]>

değişiklik akışının getirilebileceği tüm akış aralıkları.

getPartitionKeyDefinition()

Uyarı

Bu API artık kullanım dışıdır.

This method has been renamed to readPartitionKeyDefinition.

Önce önbelleğine bakarak bölüm anahtarı tanımını alır, aksi takdirde koleksiyonu okuyarak.

function getPartitionKeyDefinition(): Promise<ResourceResponse<PartitionKeyDefinition>>

Döndürülenler

getQueryPlan(string | SqlQuerySpec)

function getQueryPlan(query: string | SqlQuerySpec): Promise<Response<PartitionedQueryExecutionInfo>>

Parametreler

query

string | SqlQuerySpec

Döndürülenler

Promise<Response<PartitionedQueryExecutionInfo>>

initializeEncryption()

Kapsayıcı için şifrelemeyle ilgili önbellekleri ısıtır.

Örnek

import { ClientSecretCredential } from "@azure/identity";
import {
  AzureKeyVaultEncryptionKeyResolver,
  CosmosClient,
  EncryptionType,
  EncryptionAlgorithm,
  ClientEncryptionIncludedPath,
  ClientEncryptionPolicy,
} from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const credentials = new ClientSecretCredential("<tenant-id>", "<client-id>", "<app-secret>");
const keyResolver = new AzureKeyVaultEncryptionKeyResolver(credentials);
const client = new CosmosClient({
  endpoint,
  key,
  clientEncryptionOptions: {
    keyEncryptionKeyResolver: keyResolver,
  },
});
const { database } = await client.databases.createIfNotExists({ id: "<db id>" });

const paths = ["/path1", "/path2", "/path3"].map(
  (path) =>
    ({
      path: path,
      clientEncryptionKeyId: "< cek - id >",
      encryptionType: EncryptionType.DETERMINISTIC,
      encryptionAlgorithm: EncryptionAlgorithm.AEAD_AES_256_CBC_HMAC_SHA256,
    }) as ClientEncryptionIncludedPath,
);
const clientEncryptionPolicy: ClientEncryptionPolicy = {
  includedPaths: paths,
  policyFormatVersion: 2,
};
const containerDefinition = {
  id: "Test Container",
  partitionKey: {
    paths: ["/id"],
  },
  clientEncryptionPolicy: clientEncryptionPolicy,
};
const { container } = await database.containers.createIfNotExists(containerDefinition);

await container.initializeEncryption();
function initializeEncryption(): Promise<void>

Döndürülenler

Promise<void>

item(string, PartitionKey)

Kimliğe göre belirli bir Öğe okumak, değiştirmek veya silmek için kullanılır.

Yeni öğeler oluşturmak veya tüm öğeleri sorgulamak/okumak için .items kullanın.

Örnek

Bir öğeyi değiştirme

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const { body: replacedItem } = await container
  .item("<item id>", "<partition key value>")
  .replace({ id: "<item id>", title: "Updated post", authorID: 5 });
function item(id: string, partitionKeyValue?: PartitionKey): Item

Parametreler

id

string

Öğesinin kimliği.

partitionKeyValue
PartitionKey

Öğe bölüm anahtarının değeri

Döndürülenler

read(RequestOptions)

Kapsayıcının tanımını okuma

Örnek

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { resource: database } = await client.database("<db id>").container("<container id>").read();
function read(options?: RequestOptions): Promise<ContainerResponse>

Parametreler

options
RequestOptions

Döndürülenler

readOffer(RequestOptions)

Kapsayıcıda teklif alır. Yoksa, tanımlanmamış bir OfferResponse döndürür.

Örnek

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { resource: offer } = await client
  .database("<db id>")
  .container("<container id>")
  .readOffer();
function readOffer(options?: RequestOptions): Promise<OfferResponse>

Parametreler

options
RequestOptions

Döndürülenler

Promise<OfferResponse>

readPartitionKeyRanges(FeedOptions)

Kapsayıcı için bölüm anahtarı aralıklarını alır.

Örnek

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const { resources: ranges } = await container.readPartitionKeyRanges().fetchAll();
function readPartitionKeyRanges(feedOptions?: FeedOptions): QueryIterator<PartitionKeyRange>

Parametreler

feedOptions
FeedOptions

İstek için seçenekler.

Döndürülenler

QueryIterator<PartitionKeyRange>

Bölüm anahtarı aralıklarının yineleyicisi.

replace(ContainerDefinition, RequestOptions)

Kapsayıcının tanımını değiştirme

Örnek

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const containerDefinition = {
  id: "Test Container",
  partitionKey: {
    paths: ["/key1"],
  },
  throughput: 1000,
};
const { container } = await database.containers.createIfNotExists(containerDefinition);

containerDefinition.throughput = 400;
const { container: replacedContainer } = await container.replace(containerDefinition);
function replace(body: ContainerDefinition, options?: RequestOptions): Promise<ContainerResponse>

Parametreler

options
RequestOptions

Döndürülenler