ChangeFeedPullModelIterator interface
Use Items.getChangeFeedIterator()
to return an iterator that can iterate over all the changes for a partition key, feed range or an entire container.
Properties
has |
Always returns true, changefeed is an infinite stream. |
Methods
get |
Gets an async iterator which will yield change feed results. Example Get changefeed for an entire container from now
|
read |
Returns next set of results for the change feed. Example
|
Property Details
hasMoreResults
Always returns true, changefeed is an infinite stream.
hasMoreResults: boolean
Property Value
boolean
Method Details
getAsyncIterator()
Gets an async iterator which will yield change feed results.
Example
Get changefeed for an entire container from now
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)[]>>
Returns
AsyncIterable<ChangeFeedIteratorResponse<(T & Resource)[]>>
readNext()
Returns next set of results for the change feed.
Example
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)[]>>
Returns
Promise<ChangeFeedIteratorResponse<(T & Resource)[]>>