다음을 통해 공유


Item class

특정 항목에 대한 작업을 수행하는 데 사용됩니다.

모든 항목에 대한 작업은 항목 참조하세요. container.items참조하세요.

속성

container
id
url

리소스에 대한 참조 URL을 반환합니다. 사용 권한에서 연결에 사용됩니다.

메서드

delete<T>(RequestOptions)

항목을 삭제합니다.

제공된 모든 형식 T는 반드시 SDK에 의해 적용되지 않습니다. 더 많거나 적은 속성을 얻을 수 있으며 이를 적용하는 것은 논리에 달려 있습니다.

예제

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

interface TodoItem {
  title: string;
  done: boolean;
  id: string;
}

const { resource: item } = await container.item("id", "<pkValue>").read<TodoItem>();

await container.item("id").delete<TodoItem>();
patch<T>(PatchRequestBody, RequestOptions)

항목에서 JSONPatch를 수행합니다.

제공된 모든 형식 T는 반드시 SDK에 의해 적용되지 않습니다. 더 많거나 적은 속성을 얻을 수 있으며 이를 적용하는 것은 논리에 달려 있습니다.

예제

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

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

interface TodoItem {
  title: string;
  done: boolean;
  id: string;
}

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

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

const { resource: item } = await container.item("id", "<pkValue>").read<TodoItem>();

const { resource: patchedItem } = await container.item("id").patch<TodoItem>([
  {
    op: "replace", // Operation type (can be replace, add, remove, set, incr)
    path: "/title", // The path to the property to update
    value: "new-title", // New value for the property
  },
  {
    op: "remove",
    path: "/done",
  },
]);
read<T>(RequestOptions)

항목의 정의를 읽습니다.

제공된 모든 형식 T는 반드시 SDK에 의해 적용되지 않습니다. 더 많거나 적은 속성을 얻을 수 있으며 이를 적용하는 것은 논리에 달려 있습니다. T 형식이 클래스인 경우 일치 프로토타입이 없으므로 typeof 비교를 통과하지 않습니다. 인터페이스만 사용하는 것이 좋습니다.

JSON 항목에 대한 집합 스키마가 없습니다. 여기에는 사용자 지정 속성이 포함될 수 있습니다.

예제

응답에 사용자 지정 형식 사용

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

interface TodoItem {
  title: string;
  done: boolean;
  id: string;
}

const { resource: item } = await container.item("id", "<pkValue>").read<TodoItem>();
replace(ItemDefinition, RequestOptions)

항목의 정의를 바꿉다.

JSON 항목에 대한 집합 스키마가 없습니다. 여기에는 사용자 지정 속성이 포함될 수 있습니다.

예제

import { CosmosClient, ItemDefinition } 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 item: ItemDefinition = {
  id: "id",
  title: "new_title",
};

const { resource: replacedItem } = await container.item("id").replace(item);
replace<T>(T, RequestOptions)

항목의 정의를 바꿉다.

제공된 모든 형식 T는 반드시 SDK에 의해 적용되지 않습니다. 더 많거나 적은 속성을 얻을 수 있으며 이를 적용하는 것은 논리에 달려 있습니다.

JSON 항목에 대한 집합 스키마가 없습니다. 여기에는 사용자 지정 속성이 포함될 수 있습니다.

예제

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

interface TodoItem {
  title: string;
  done: boolean;
  id: string;
}

const { resource: item } = await container.item("id", "<pkValue>").read<TodoItem>();

item.done = true;
const { resource: replacedItem } = await container.item("id").replace<TodoItem>(item);

속성 세부 정보

container

container: Container

속성 값

id

id: string

속성 값

string

url

리소스에 대한 참조 URL을 반환합니다. 사용 권한에서 연결에 사용됩니다.

string url

속성 값

string

메서드 세부 정보

delete<T>(RequestOptions)

항목을 삭제합니다.

제공된 모든 형식 T는 반드시 SDK에 의해 적용되지 않습니다. 더 많거나 적은 속성을 얻을 수 있으며 이를 적용하는 것은 논리에 달려 있습니다.

예제

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

interface TodoItem {
  title: string;
  done: boolean;
  id: string;
}

const { resource: item } = await container.item("id", "<pkValue>").read<TodoItem>();

await container.item("id").delete<TodoItem>();
function delete<T>(options?: RequestOptions): Promise<ItemResponse<T>>

매개 변수

options
RequestOptions

요청에 대한 추가 옵션

반환

Promise<ItemResponse<T>>

patch<T>(PatchRequestBody, RequestOptions)

항목에서 JSONPatch를 수행합니다.

제공된 모든 형식 T는 반드시 SDK에 의해 적용되지 않습니다. 더 많거나 적은 속성을 얻을 수 있으며 이를 적용하는 것은 논리에 달려 있습니다.

예제

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

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

interface TodoItem {
  title: string;
  done: boolean;
  id: string;
}

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

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

const { resource: item } = await container.item("id", "<pkValue>").read<TodoItem>();

const { resource: patchedItem } = await container.item("id").patch<TodoItem>([
  {
    op: "replace", // Operation type (can be replace, add, remove, set, incr)
    path: "/title", // The path to the property to update
    value: "new-title", // New value for the property
  },
  {
    op: "remove",
    path: "/done",
  },
]);
function patch<T>(body: PatchRequestBody, options?: RequestOptions): Promise<ItemResponse<T>>

매개 변수

options
RequestOptions

요청에 대한 추가 옵션

반환

Promise<ItemResponse<T>>

read<T>(RequestOptions)

항목의 정의를 읽습니다.

제공된 모든 형식 T는 반드시 SDK에 의해 적용되지 않습니다. 더 많거나 적은 속성을 얻을 수 있으며 이를 적용하는 것은 논리에 달려 있습니다. T 형식이 클래스인 경우 일치 프로토타입이 없으므로 typeof 비교를 통과하지 않습니다. 인터페이스만 사용하는 것이 좋습니다.

JSON 항목에 대한 집합 스키마가 없습니다. 여기에는 사용자 지정 속성이 포함될 수 있습니다.

예제

응답에 사용자 지정 형식 사용

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

interface TodoItem {
  title: string;
  done: boolean;
  id: string;
}

const { resource: item } = await container.item("id", "<pkValue>").read<TodoItem>();
function read<T>(options?: RequestOptions): Promise<ItemResponse<T>>

매개 변수

options
RequestOptions

요청에 대한 추가 옵션

반환

Promise<ItemResponse<T>>

replace(ItemDefinition, RequestOptions)

항목의 정의를 바꿉다.

JSON 항목에 대한 집합 스키마가 없습니다. 여기에는 사용자 지정 속성이 포함될 수 있습니다.

예제

import { CosmosClient, ItemDefinition } 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 item: ItemDefinition = {
  id: "id",
  title: "new_title",
};

const { resource: replacedItem } = await container.item("id").replace(item);
function replace(body: ItemDefinition, options?: RequestOptions): Promise<ItemResponse<ItemDefinition>>

매개 변수

body
ItemDefinition

기존 Item정의를 대체할 정의입니다.

options
RequestOptions

요청에 대한 추가 옵션

반환

replace<T>(T, RequestOptions)

항목의 정의를 바꿉다.

제공된 모든 형식 T는 반드시 SDK에 의해 적용되지 않습니다. 더 많거나 적은 속성을 얻을 수 있으며 이를 적용하는 것은 논리에 달려 있습니다.

JSON 항목에 대한 집합 스키마가 없습니다. 여기에는 사용자 지정 속성이 포함될 수 있습니다.

예제

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

interface TodoItem {
  title: string;
  done: boolean;
  id: string;
}

const { resource: item } = await container.item("id", "<pkValue>").read<TodoItem>();

item.done = true;
const { resource: replacedItem } = await container.item("id").replace<TodoItem>(item);
function replace<T>(body: T, options?: RequestOptions): Promise<ItemResponse<T>>

매개 변수

body

T

기존 Item정의를 대체할 정의입니다.

options
RequestOptions

요청에 대한 추가 옵션

반환

Promise<ItemResponse<T>>