Items class
新しい項目を作成し、すべての項目の読み取り/クエリを実行するための操作
既存のコンテナーの読み取り、置換、または削除については、項目の を参照してください。.item(id)
を使用します。
プロパティ
container |
メソッド
batch(Operation |
アイテムに対してトランザクション バッチ操作を実行します。 Batch は、操作の実行内容に基づいて型指定された操作の配列を受け取ります。 Batch はトランザクションであり、失敗した場合は、すべての操作がロールバックされます。 選択肢は、作成、アップサート、読み取り、置換、および削除です。 使用例:
|
bulk(Operation |
アイテムに対して一括操作を実行します。 一括処理は、操作の実行内容に基づいて型指定された操作の配列を受け取ります。 選択肢は、作成、アップサート、読み取り、置換、および削除です。 使用例:
|
change |
変更のページを反復処理する |
change |
変更のページを反復処理する 例 変更フィードの先頭から読み取ります。
|
change |
変更のページを反復処理する |
change |
変更のページを反復処理する |
create<T>(T, Request |
アイテムを作成します。 指定された型 T は、必ずしも SDK によって適用されるとは限りません。 多かれ少なかれプロパティを取得する場合があり、それを適用するのはロジック次第です。 JSON 項目のスキーマは設定されていません。 任意の数のカスタム プロパティを含む場合があります。 例 アイテムを作成します。
|
execute |
アイテムに対して一括操作を実行します。 例
|
get |
変更のページを反復処理する反復子を返します。 返される反復子を使用して、単一のパーティション キー、フィード範囲、またはコンテナー全体の変更をフェッチできます。 例
|
get |
暗号化されたコンテナ内のすべてのアイテムをクエリします。 例 すべての項目を配列に読み取る。
|
query(string | Sql |
すべての項目を照会します。 例 すべての項目を配列に読み取る。
|
query<T>(string | Sql |
すべての項目を照会します。 例 すべての項目を配列に読み取る。
|
read |
すべてのアイテムを読み取る。 JSON 項目のスキーマは設定されていません。 任意の数のカスタム プロパティを含む場合があります。 例 すべての項目を配列に読み取る。
|
read |
すべてのアイテムを読み取る。 指定された型 T は、必ずしも SDK によって適用されるとは限りません。 多かれ少なかれプロパティを取得する場合があり、それを適用するのはロジック次第です。 JSON 項目のスキーマは設定されていません。 任意の数のカスタム プロパティを含む場合があります。 例 すべての項目を配列に読み取る。
|
read |
変更のページを反復処理する |
read |
変更のページを反復処理する 例 変更フィードの先頭から読み取ります。
|
read |
変更のページを反復処理する |
read |
変更のページを反復処理する |
upsert(unknown, Request |
アイテムをアップサートします。 JSON 項目のスキーマは設定されていません。 任意の数のカスタム プロパティを含む場合があります。 |
upsert<T>(T, Request |
アイテムをアップサートします。 指定された型 T は、必ずしも SDK によって適用されるとは限りません。 多かれ少なかれプロパティを取得する場合があり、それを適用するのはロジック次第です。 JSON 項目のスキーマは設定されていません。 任意の数のカスタム プロパティを含む場合があります。 例 アイテムをアップサートします。
|
プロパティの詳細
container
メソッドの詳細
batch(OperationInput[], PartitionKey, RequestOptions)
アイテムに対してトランザクション バッチ操作を実行します。
Batch は、操作の実行内容に基づいて型指定された操作の配列を受け取ります。 Batch はトランザクションであり、失敗した場合は、すべての操作がロールバックされます。 選択肢は、作成、アップサート、読み取り、置換、および削除です。
使用例:
import { CosmosClient, OperationInput } 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" });
// The partitionKey is a required second argument. If it’s undefined, it defaults to the expected partition key format.
const operations: OperationInput[] = [
{
operationType: "Create",
resourceBody: { id: "doc1", name: "sample", key: "A" },
},
{
operationType: "Upsert",
resourceBody: { id: "doc2", name: "other", key: "A" },
},
];
await container.items.batch(operations, "A");
function batch(operations: OperationInput[], partitionKey?: PartitionKey, options?: RequestOptions): Promise<Response<OperationResponse[]>>
パラメーター
- operations
操作の一覧。 制限 100
- partitionKey
- PartitionKey
- options
- RequestOptions
要求の変更に使用されます
戻り値
Promise<Response<OperationResponse[]>>
bulk(OperationInput[], BulkOptions, RequestOptions)
アイテムに対して一括操作を実行します。
一括処理は、操作の実行内容に基づいて型指定された操作の配列を受け取ります。 選択肢は、作成、アップサート、読み取り、置換、および削除です。
使用例:
import { CosmosClient, OperationInput } 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 is optional at the top level if present in the resourceBody
const operations: OperationInput[] = [
{
operationType: "Create",
resourceBody: { id: "doc1", name: "sample", key: "A" },
},
{
operationType: "Upsert",
partitionKey: "A",
resourceBody: { id: "doc2", name: "other", key: "A" },
},
];
await container.items.bulk(operations);
function bulk(operations: OperationInput[], bulkOptions?: BulkOptions, options?: RequestOptions): Promise<BulkOperationResponse>
パラメーター
- operations
操作の一覧。 制限 100
- bulkOptions
- BulkOptions
一括動作を変更するオプション の options オブジェクト。 {continueOnError: false } を渡して、失敗した場合に操作の実行を停止します。 (既定値は true)
- options
- RequestOptions
要求の変更に使用されます。
戻り値
Promise<BulkOperationResponse>
changeFeed(ChangeFeedOptions)
警告
この API は非推奨になりました。
Use getChangeFeedIterator
instead.
変更のページを反復処理する ChangeFeedIterator
を作成する
function changeFeed(changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<any>
パラメーター
- changeFeedOptions
- ChangeFeedOptions
戻り値
ChangeFeedIterator<any>
changeFeed(PartitionKey, ChangeFeedOptions)
警告
この API は非推奨になりました。
Use getChangeFeedIterator
instead.
変更のページを反復処理する ChangeFeedIterator
を作成する
例
変更フィードの先頭から読み取ります。
const iterator = items.readChangeFeed({ startFromBeginning: true });
const firstPage = await iterator.fetchNext();
const firstPageResults = firstPage.result
const secondPage = await iterator.fetchNext();
function changeFeed(partitionKey: PartitionKey, changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<any>
パラメーター
- partitionKey
- PartitionKey
- changeFeedOptions
- ChangeFeedOptions
戻り値
ChangeFeedIterator<any>
changeFeed<T>(ChangeFeedOptions)
警告
この API は非推奨になりました。
Use getChangeFeedIterator
instead.
変更のページを反復処理する ChangeFeedIterator
を作成する
function changeFeed<T>(changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<T>
パラメーター
- changeFeedOptions
- ChangeFeedOptions
戻り値
changeFeed<T>(PartitionKey, ChangeFeedOptions)
警告
この API は非推奨になりました。
Use getChangeFeedIterator
instead.
変更のページを反復処理する ChangeFeedIterator
を作成する
function changeFeed<T>(partitionKey: PartitionKey, changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<T>
パラメーター
- partitionKey
- PartitionKey
- changeFeedOptions
- ChangeFeedOptions
戻り値
create<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" });
const { resource: createdItem } = await container.items.create({
id: "<item id>",
properties: {},
});
function create<T>(body: T, options?: RequestOptions): Promise<ItemResponse<T>>
パラメーター
- body
-
T
アイテムの本文を表します。 任意の数のユーザー定義プロパティを含めることができます。
- options
- RequestOptions
要求の変更 (パーティション キーの指定など) に使用されます。
戻り値
Promise<ItemResponse<T>>
executeBulkOperations(OperationInput[], RequestOptions)
アイテムに対して一括操作を実行します。
例
import { CosmosClient, OperationInput } 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 operations: OperationInput[] = [
{
operationType: "Create",
resourceBody: { id: "doc1", name: "sample", key: "A" },
},
{
operationType: "Upsert",
partitionKey: "A",
resourceBody: { id: "doc2", name: "other", key: "A" },
},
];
await container.items.executeBulkOperations(operations);
function executeBulkOperations(operations: OperationInput[], options?: RequestOptions): Promise<BulkOperationResult[]>
パラメーター
- operations
操作の一覧
- options
- RequestOptions
要求の変更に使用されます
戻り値
Promise<BulkOperationResult[]>
操作に対応する操作結果の一覧
getChangeFeedIterator<T>(ChangeFeedIteratorOptions)
変更のページを反復処理する反復子を返します。 返される反復子を使用して、単一のパーティション キー、フィード範囲、またはコンテナー全体の変更をフェッチできます。
例
import {
CosmosClient,
PartitionKeyDefinitionVersion,
PartitionKeyKind,
ChangeFeedStartFrom,
} 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 Database",
partitionKey: {
paths: ["/name", "/address/zip"],
version: PartitionKeyDefinitionVersion.V2,
kind: PartitionKeyKind.MultiHash,
},
};
const { container } = await database.containers.createIfNotExists(containerDefinition);
const partitionKey = "some-partition-Key-value";
const options = {
changeFeedStartFrom: ChangeFeedStartFrom.Beginning(partitionKey),
};
const iterator = container.items.getChangeFeedIterator(options);
while (iterator.hasMoreResults) {
const response = await iterator.readNext();
// process this response
}
function getChangeFeedIterator<T>(changeFeedIteratorOptions?: ChangeFeedIteratorOptions): ChangeFeedPullModelIterator<T>
パラメーター
- changeFeedIteratorOptions
- ChangeFeedIteratorOptions
戻り値
getEncryptionQueryIterator(EncryptionQueryBuilder, FeedOptions)
暗号化されたコンテナ内のすべてのアイテムをクエリします。
例
すべての項目を配列に読み取る。
import { CosmosClient, EncryptionQueryBuilder } 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 queryBuilder = new EncryptionQueryBuilder(
`SELECT firstname FROM Families f WHERE f.lastName = @lastName`,
);
queryBuilder.addParameter("@lastName", "Hendricks", "/lastname");
const queryIterator = await container.items.getEncryptionQueryIterator(queryBuilder);
const { resources: items } = await queryIterator.fetchAll();
function getEncryptionQueryIterator(queryBuilder: EncryptionQueryBuilder, options?: FeedOptions): Promise<QueryIterator<ItemDefinition>>
パラメーター
- queryBuilder
- EncryptionQueryBuilder
操作のクエリ構成。 暗号化されたプロパティに対してクエリを作成する方法の詳細については、「 SqlQuerySpec 」を参照してください。
- options
- FeedOptions
要求の変更 (パーティション キーの指定など) に使用されます。
戻り値
Promise<QueryIterator<ItemDefinition>>
query(string | SqlQuerySpec, FeedOptions)
すべての項目を照会します。
例
すべての項目を配列に読み取る。
import { CosmosClient, SqlQuerySpec } 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 querySpec: SqlQuerySpec = {
query: `SELECT * FROM Families f WHERE f.lastName = @lastName`,
parameters: [{ name: "@lastName", value: "Hendricks" }],
};
const { resources: items } = await container.items.query(querySpec).fetchAll();
function query(query: string | SqlQuerySpec, options?: FeedOptions): QueryIterator<any>
パラメーター
- query
-
string | SqlQuerySpec
操作のクエリ構成。 クエリ 構成する方法の詳細については、SqlQuerySpec を参照してください。
- options
- FeedOptions
要求の変更 (パーティション キーの指定など) に使用されます。
戻り値
QueryIterator<any>
query<T>(string | SqlQuerySpec, FeedOptions)
すべての項目を照会します。
例
すべての項目を配列に読み取る。
import { CosmosClient, SqlQuerySpec } 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 querySpec: SqlQuerySpec = {
query: `SELECT * FROM Families f WHERE f.lastName = @lastName`,
parameters: [{ name: "@lastName", value: "Hendricks" }],
};
const { resources: items } = await container.items.query(querySpec).fetchAll();
function query<T>(query: string | SqlQuerySpec, options?: FeedOptions): QueryIterator<T>
パラメーター
- query
-
string | SqlQuerySpec
操作のクエリ構成。 クエリ 構成する方法の詳細については、SqlQuerySpec を参照してください。
- options
- FeedOptions
要求の変更 (パーティション キーの指定など) に使用されます。
戻り値
readAll(FeedOptions)
すべてのアイテムを読み取る。
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" });
const { resources: containerList } = await container.items.readAll().fetchAll();
function readAll(options?: FeedOptions): QueryIterator<ItemDefinition>
パラメーター
- options
- FeedOptions
要求の変更 (パーティション キーの指定など) に使用されます。
戻り値
readAll<T>(FeedOptions)
すべてのアイテムを読み取る。
指定された型 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" });
const { resources: containerList } = await container.items.readAll().fetchAll();
function readAll<T>(options?: FeedOptions): QueryIterator<T>
パラメーター
- options
- FeedOptions
要求の変更 (パーティション キーの指定など) に使用されます。
戻り値
readChangeFeed(ChangeFeedOptions)
警告
この API は非推奨になりました。
Use getChangeFeedIterator
instead.
変更のページを反復処理する ChangeFeedIterator
を作成する
function readChangeFeed(changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<any>
パラメーター
- changeFeedOptions
- ChangeFeedOptions
戻り値
ChangeFeedIterator<any>
readChangeFeed(PartitionKey, ChangeFeedOptions)
警告
この API は非推奨になりました。
Use getChangeFeedIterator
instead.
変更のページを反復処理する ChangeFeedIterator
を作成する
例
変更フィードの先頭から読み取ります。
const iterator = items.readChangeFeed({ startFromBeginning: true });
const firstPage = await iterator.fetchNext();
const firstPageResults = firstPage.result
const secondPage = await iterator.fetchNext();
function readChangeFeed(partitionKey: PartitionKey, changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<any>
パラメーター
- partitionKey
- PartitionKey
- changeFeedOptions
- ChangeFeedOptions
戻り値
ChangeFeedIterator<any>
readChangeFeed<T>(ChangeFeedOptions)
警告
この API は非推奨になりました。
Use getChangeFeedIterator
instead.
変更のページを反復処理する ChangeFeedIterator
を作成する
function readChangeFeed<T>(changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<T>
パラメーター
- changeFeedOptions
- ChangeFeedOptions
戻り値
readChangeFeed<T>(PartitionKey, ChangeFeedOptions)
警告
この API は非推奨になりました。
Use getChangeFeedIterator
instead.
変更のページを反復処理する ChangeFeedIterator
を作成する
function readChangeFeed<T>(partitionKey: PartitionKey, changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<T>
パラメーター
- partitionKey
- PartitionKey
- changeFeedOptions
- ChangeFeedOptions
戻り値
upsert(unknown, RequestOptions)
アイテムをアップサートします。
JSON 項目のスキーマは設定されていません。 任意の数のカスタム プロパティを含む場合があります。
function upsert(body: unknown, options?: RequestOptions): Promise<ItemResponse<ItemDefinition>>
パラメーター
- body
-
unknown
アイテムの本文を表します。 任意の数のユーザー定義プロパティを含めることができます。
- options
- RequestOptions
要求の変更 (パーティション キーの指定など) に使用されます。
戻り値
Promise<ItemResponse<ItemDefinition>>
upsert<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" });
const { resource: createdItem1 } = await container.items.create({
id: "<item id 1>",
properties: {},
});
const { resource: upsertItem1 } = await container.items.upsert({
id: "<item id 1>",
updated_properties: {},
});
const { resource: upsertItem2 } = await container.items.upsert({
id: "<item id 2>",
properties: {},
});
function upsert<T>(body: T, options?: RequestOptions): Promise<ItemResponse<T>>
パラメーター
- body
-
T
アイテムの本文を表します。 任意の数のユーザー定義プロパティを含めることができます。
- options
- RequestOptions
要求の変更 (パーティション キーの指定など) に使用されます。
戻り値
Promise<ItemResponse<T>>