@azure/cosmos 4.9.0-alpha.20251201.1 → 4.9.0-alpha.20251204.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -399,6 +399,77 @@ const { resources } = await container.items
|
|
|
399
399
|
.fetchAll();
|
|
400
400
|
```
|
|
401
401
|
|
|
402
|
+
**Note:** To use continuation tokens with queries, ensure that `enableQueryControl` is set to `true` in the query options. This enables support for retrieving query continuation tokens for paginating through large result sets.
|
|
403
|
+
|
|
404
|
+
Here's an example of using continuation tokens with `enableQueryControl`:
|
|
405
|
+
|
|
406
|
+
```ts snippet:QueryWithContinuationToken
|
|
407
|
+
import { CosmosClient } from "@azure/cosmos";
|
|
408
|
+
|
|
409
|
+
const endpoint = "https://your-account.documents.azure.com";
|
|
410
|
+
const key = "<database account masterkey>";
|
|
411
|
+
const client = new CosmosClient({ endpoint, key });
|
|
412
|
+
|
|
413
|
+
const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
|
|
414
|
+
|
|
415
|
+
const { container } = await database.containers.createIfNotExists({ id: "Test Container" });
|
|
416
|
+
|
|
417
|
+
const queryIterator = container.items.query("SELECT * from c", {
|
|
418
|
+
maxItemCount: 10,
|
|
419
|
+
enableQueryControl: true,
|
|
420
|
+
forceQueryPlan: true,
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
let pageCount = 0;
|
|
424
|
+
while (queryIterator.hasMoreResults()) {
|
|
425
|
+
pageCount++;
|
|
426
|
+
const { resources, continuationToken } = await queryIterator.fetchNext();
|
|
427
|
+
console.log(`Page ${pageCount} has ${resources.length} items`);
|
|
428
|
+
// continuationToken can be saved and used later to resume from where you left off
|
|
429
|
+
}
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
**Special case: ORDER BY queries**
|
|
433
|
+
|
|
434
|
+
When using `enableQueryControl` with ORDER BY queries, be aware that the continuation token behavior requires special handling:
|
|
435
|
+
|
|
436
|
+
```ts snippet:QueryWithContinuationTokenOrderBy
|
|
437
|
+
import { CosmosClient } from "@azure/cosmos";
|
|
438
|
+
|
|
439
|
+
const endpoint = "https://your-account.documents.azure.com";
|
|
440
|
+
const key = "<database account masterkey>";
|
|
441
|
+
const client = new CosmosClient({ endpoint, key });
|
|
442
|
+
|
|
443
|
+
const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
|
|
444
|
+
|
|
445
|
+
const { container } = await database.containers.createIfNotExists({ id: "Test Container" });
|
|
446
|
+
|
|
447
|
+
const queryIterator = container.items.query("SELECT * from c ORDER BY c.id", {
|
|
448
|
+
maxItemCount: 10,
|
|
449
|
+
enableQueryControl: true,
|
|
450
|
+
forceQueryPlan: true,
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
let pageCount = 0;
|
|
454
|
+
while (queryIterator.hasMoreResults()) {
|
|
455
|
+
pageCount++;
|
|
456
|
+
const { resources, continuationToken } = await queryIterator.fetchNext();
|
|
457
|
+
if (resources.length > 0) {
|
|
458
|
+
// Process results
|
|
459
|
+
// Safe to use continuationToken after receiving data
|
|
460
|
+
if (continuationToken) {
|
|
461
|
+
// Can persist token for resuming later
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
**Important:** When using `enableQueryControl` with ORDER BY queries:
|
|
468
|
+
- The `resources` array and `continuationToken` may be empty and `undefined` repectively during the initial calls
|
|
469
|
+
- This occurs because the query needs to consolidate results across partitions before returning
|
|
470
|
+
- Always verify `resources.length > 0` before relying on the continuation token
|
|
471
|
+
- Use `forceQueryPlan: true` in your query options to ensure consistent query execution behavior across partitions, which helps with continuation token stability
|
|
472
|
+
|
|
402
473
|
For more information on querying Cosmos DB databases using the SQL API, see [Query Azure Cosmos DB data with SQL queries][cosmos_sql_queries].
|
|
403
474
|
|
|
404
475
|
### Change Feed Pull Model
|
|
@@ -741,6 +812,7 @@ Currently the features below are **not supported**. For alternatives options, ch
|
|
|
741
812
|
- Change Feed: Processor
|
|
742
813
|
- Change Feed: Read multiple partitions key values
|
|
743
814
|
- Cross-partition ORDER BY for mixed types
|
|
815
|
+
- We recommend upgrading to the latest SDK to use continuation tokens for pagination. When using continuation tokens with `enableQueryControl` on cross-partition queries (queries that scan multiple partitions), ensure you set `forceQueryPlan: true` in query options to enforce a deterministic execution plan. Without it, query execution behavior may vary across partitions, affecting continuation token consistency.
|
|
744
816
|
|
|
745
817
|
### Control Plane Limitations:
|
|
746
818
|
|
|
@@ -750,9 +822,9 @@ Currently the features below are **not supported**. For alternatives options, ch
|
|
|
750
822
|
|
|
751
823
|
## Workarounds
|
|
752
824
|
|
|
753
|
-
### Continuation token for cross partitions queries
|
|
825
|
+
### Continuation token for cross partitions queries for older versions(< 4.9.0)
|
|
754
826
|
|
|
755
|
-
You can achieve cross partition queries with continuation token support by using
|
|
827
|
+
You can achieve cross partition queries with continuation token support for older versions before 4.9.0 by using
|
|
756
828
|
[Side car pattern](https://github.com/Azure-Samples/Cosmosdb-query-sidecar).
|
|
757
829
|
This pattern can also enable applications to be composed of heterogeneous components and technologies.
|
|
758
830
|
|