你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

ChangeFeedPullModelIterator interface

使用 Items.getChangeFeedIterator() 返回一个迭代器,该迭代器可以循环访问分区键、源范围或整个容器的所有更改。

属性

hasMoreResults

始终返回 true,更改源是无限流。

方法

getAsyncIterator()

获取一个异步迭代器,该迭代器将产生更改源结果。

示例

从现在起获取整个容器的更改源

import { CosmosClient, 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 { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const options = { changeFeedStartFrom: ChangeFeedStartFrom.Now() };
for await (const results of container.items.getChangeFeedIterator(options).getAsyncIterator()) {
  // Process result
  for (const resource of results.result) {
    console.log(resource);
  }
}
readNext()

返回更改源的下一组结果。

示例

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
}

属性详细信息

hasMoreResults

始终返回 true,更改源是无限流。

hasMoreResults: boolean

属性值

boolean

方法详细信息

getAsyncIterator()

获取一个异步迭代器,该迭代器将产生更改源结果。

示例

从现在起获取整个容器的更改源

import { CosmosClient, 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 { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const options = { changeFeedStartFrom: ChangeFeedStartFrom.Now() };
for await (const results of container.items.getChangeFeedIterator(options).getAsyncIterator()) {
  // Process result
  for (const resource of results.result) {
    console.log(resource);
  }
}
function getAsyncIterator(): AsyncIterable<ChangeFeedIteratorResponse<(T & Resource)[]>>

返回

AsyncIterable<ChangeFeedIteratorResponse<(T & Resource)[]>>

readNext()

返回更改源的下一组结果。

示例

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 readNext(): Promise<ChangeFeedIteratorResponse<(T & Resource)[]>>

返回