Container class
ID로 특정 기존 컨테이너를 읽거나, 대체하거나, 삭제하기 위한 작업입니다.
새 컨테이너를 만들고 모든 컨테이너를 읽고 쿼리하려면 컨테이너 참조하세요. .containers사용합니다.
참고: 이러한 모든 작업은 고정 예산에 대해 호출합니다.
이러한 호출이 애플리케이션을 사용하여 하위 선형으로 확장되도록 시스템을 디자인해야 합니다.
예를 들어 컨테이너가 있는지 확인하기 위해 모든 단일 container(id).read() 호출하기 전에 item.read() 호출하지 마세요. 애플리케이션 시작 시 이 작업을 한 번 수행합니다.
속성
| conflicts | 지정된 컨테이너에 대한 충돌을 읽고 쿼리하는 작업입니다. 특정 충돌을 읽거나 삭제하려면 |
| database | |
| id | |
| items | 새 항목을 만들고 모든 항목을 읽고 쿼리하는 작업 기존 항목을 읽거나 대체하거나 삭제하려면 예제 새 항목 만들기
|
| scripts | 저장 프로시저, 트리거 및 사용자 정의 함수에 대한 모든 작업 |
| url | 리소스에 대한 참조 URL을 반환합니다. 사용 권한에서 연결에 사용됩니다. |
메서드
| conflict(string, Partition |
ID별로 특정 기존 충돌 읽거나 바꾸거나 삭제하는 데 사용됩니다.
예제
|
| delete(Request |
컨테이너 삭제 예제
|
| delete |
제공된 파티션 키 값에 대한 컨테이너에 속한 모든 문서 삭제 예제
|
| get |
예제
|
| get |
컬렉션을 읽어 캐시를 조사하여 먼저 파티션 키 정의를 가져옵니다. |
| get |
|
| initialize |
컨테이너에 대한 암호화 관련 캐시를 워밍업합니다. 예제
|
| item(string, Partition |
ID별로 특정 기존 항목 읽거나 바꾸거나 삭제하는 데 사용됩니다.
예제 항목 바꾸기
|
| read(Request |
컨테이너의 정의 읽기 예제
|
| read |
컨테이너에 대한 제안을 가져옵니다. 없는 경우 정의되지 않은 OfferResponse를 반환합니다. 예제
|
| read |
컨테이너의 파티션 키 범위를 가져옵니다. 예제
|
| replace(Container |
컨테이너의 정의 바꾸기 예제
|
속성 세부 정보
conflicts
지정된 컨테이너에 대한 충돌을 읽고 쿼리하는 작업입니다.
특정 충돌을 읽거나 삭제하려면 .conflict(id)사용합니다.
Conflicts conflicts
속성 값
database
id
id: string
속성 값
string
items
새 항목을 만들고 모든 항목을 읽고 쿼리하는 작업
기존 항목을 읽거나 대체하거나 삭제하려면 .item(id)사용합니다.
예제
새 항목 만들기
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
속성 값
scripts
url
리소스에 대한 참조 URL을 반환합니다. 사용 권한에서 연결에 사용됩니다.
string url
속성 값
string
메서드 세부 정보
conflict(string, PartitionKey)
ID별로 특정 기존 충돌 읽거나 바꾸거나 삭제하는 데 사용됩니다.
.conflicts 사용하여 새 충돌을 만들거나 모든 충돌을 쿼리/읽습니다.
예제
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
매개 변수
- id
-
string
충돌ID입니다.
- partitionKey
- PartitionKey
반환
delete(RequestOptions)
컨테이너 삭제
예제
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>
매개 변수
- options
- RequestOptions
반환
Promise<ContainerResponse>
deleteAllItemsForPartitionKey(PartitionKey, RequestOptions)
제공된 파티션 키 값에 대한 컨테이너에 속한 모든 문서 삭제
예제
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>
매개 변수
- partitionKey
- PartitionKey
삭제할 항목의 파티션 키 값입니다.
- options
- RequestOptions
반환
Promise<ContainerResponse>
getFeedRanges()
예제
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[]>
반환
Promise<readonly FeedRange[]>
변경 피드를 가져올 수 있는 모든 피드 범위입니다.
getPartitionKeyDefinition()
경고
이 API는 이제 사용되지 않습니다.
This method has been renamed to readPartitionKeyDefinition.
컬렉션을 읽어 캐시를 조사하여 먼저 파티션 키 정의를 가져옵니다.
function getPartitionKeyDefinition(): Promise<ResourceResponse<PartitionKeyDefinition>>
반환
Promise<ResourceResponse<PartitionKeyDefinition>>
getQueryPlan(string | SqlQuerySpec)
function getQueryPlan(query: string | SqlQuerySpec): Promise<Response<PartitionedQueryExecutionInfo>>
매개 변수
- query
-
string | SqlQuerySpec
반환
Promise<Response<PartitionedQueryExecutionInfo>>
initializeEncryption()
컨테이너에 대한 암호화 관련 캐시를 워밍업합니다.
예제
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>
반환
Promise<void>
item(string, PartitionKey)
ID별로 특정 기존 항목 읽거나 바꾸거나 삭제하는 데 사용됩니다.
.items 사용하여 새 항목을 만들거나 모든 항목을 쿼리/읽습니다.
예제
항목 바꾸기
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
매개 변수
- id
-
string
항목ID입니다.
- partitionKeyValue
- PartitionKey
Item 파티션 키의 값입니다.
반환
read(RequestOptions)
컨테이너의 정의 읽기
예제
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>
매개 변수
- options
- RequestOptions
반환
Promise<ContainerResponse>
readOffer(RequestOptions)
컨테이너에 대한 제안을 가져옵니다. 없는 경우 정의되지 않은 OfferResponse를 반환합니다.
예제
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>
매개 변수
- options
- RequestOptions
반환
Promise<OfferResponse>
readPartitionKeyRanges(FeedOptions)
컨테이너의 파티션 키 범위를 가져옵니다.
예제
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>
매개 변수
- feedOptions
- FeedOptions
요청에 대한 옵션입니다.
반환
QueryIterator<PartitionKeyRange>
파티션 키 범위의 반복자입니다.
replace(ContainerDefinition, RequestOptions)
컨테이너의 정의 바꾸기
예제
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>
매개 변수
- body
- ContainerDefinition
- options
- RequestOptions
반환
Promise<ContainerResponse>