2

Cassandra 的 Stargate 文档 API 提供页面大小以返回受页面大小限制的所有文档。页面大小的最大值为 20。如何获取下一个文档;即21到30?

使用 Stargate API for Cassandra 读取文档

4

1 回答 1

2

因此,当您针对最初的 20 个运行查询时,您将在返回的 JSON 中获得一个名为 pageState. 这是一个例子page-size=5

% curl --request GET \
  --url https://$ASTRA_DB_ID-$ASTRA_DB_REGION.apps.astra.datastax.com/api/rest/v2/namespaces/$ASTRA_DB_KEYSPACE/collections/hello_docs\?page-size\=5 \
  -H "X-Cassandra-Token: $ASTRA_DB_APPLICATION_TOKEN" \
  -H 'Content-Type: application/json'
{"pageState":"JGNlYjczMDc5LTE1NTItNGQyNS1hM2ExLWE2MzgxNWVlYTAyMADwf_____B_____","data":{
"58b12778-0efd-466e-89bf-66a4c99adee1":{"author":"Tom Clancy","title":"Red Rabbit"},
"77fe8690-f8d4-43b8-b1c9-a328318d4eae":{"author":"Tom Clancy","title":"Every Man a Tiger"},
"3177f86c-a633-4302-92a5-de4c15ab5840":{"author":"Tom Clancy","title":"Rainbow Six"},
"cefc7117-fc73-47b8-a965-099cf3a59269":{"author":"Tom Clancy","title":"Clear and Present Danger"},
"ceb73079-1552-4d25-a3a1-a63815eea020":{"author":"Tom Clancy","title":"The Cardinal of the Kremlin"}}}%

当我想获取接下来的 5 个文档时,我重新运行相同的查询,但将page-state参数添加为先前结果返回的值:

&page-state\=JGNlYjczMDc5LTE1NTItNGQyNS1hM2ExLWE2MzgxNWVlYTAyMADwf_____B_____

当我将它添加到原始查询时,它看起来像这样:

% curl --request GET \
--url https://$ASTRA_DB_ID-$ASTRA_DB_REGION.apps.astra.datastax.com/api/rest/v2/namespaces/$ASTRA_DB_KEYSPACE/collections/hello_docs\?page-size\=5\&page-state\=JGNlYjczMDc5LTE1NTItNGQyNS1hM2ExLWE2MzgxNWVlYTAyMADwf_____B_____ \
-H "X-Cassandra-Token: $ASTRA_DB_APPLICATION_TOKEN" \
-H 'Content-Type: application/json'

 {"pageState":"JDUxMzVmMzFiLWY4NDYtNGZiNy1iNmFmLTk2YmU2OTMyNzlmMQDwf_____B_____","data":{
"f42cc7d8-81ba-41d5-b5c9-c13f8d0009c6":{"author":"Tom Clancy","title":"Patriot Games"},
"46df315f-7208-4859-af1c-96c4953f70c7":{"author":"Tom Clancy","title":"Without Remorse"},
"b23af545-4fdc-4ac5-907a-7132d7429d26":{"author":"Tom Clancy","title":"The Hunt for Red October"},
"c6d55ecd-1631-4d5c-8320-d111662f8837":{"other":"This is nonsensical stuff.","title":"Some Stuff"},
"5135f31b-f846-4fb7-b6af-96be693279f1":{"author":"Tom Clancy","title":"The Sum of all Fears"}}}%

tl;博士;

pageState返回的结果添加到结果中,您应该得到下一个 20。

编辑 20211011

Stargate 文档已详细更新以解决此过程。

使用分页检索所有文档

于 2021-09-17T19:50:05.067 回答