问题
I know that if the continuation token is null (the whole token json is null), that means there will be no more data in the next request.
In my case, I checked that there is definitely no more data in the next page, and the token is supposed to be null. But it returns this "half" null token...
And the token looks something like this:
"{\"token\":null,\"range\":{\"min\":\"xxxxxxxxxx\",\"max\":\"xxxxxxxxxx\"}}"
Only the token is null, but min
and max
are not null, what does it indicate? In another word, should I use continuation == null
or continuation.token == null
to see whether there is more data in the next page?
回答1:
For some background context:
- Cosmos DB is a distributed database, in which data and requests are partitioned across multiple backend servers (to scale storage and throughput beyond a single server).
- I bring this up because you may perform queries that are routed to a single partition (by including the partition key in the WHERE / filter clause of your query) - as well as perform queries that fan out across multiple partitions.
- Within the scope of each partition - query results are returned in a paginated manner.
- To learn more about partitioning - see: https://docs.microsoft.com/en-us/azure/cosmos-db/partition-data
The token you are seeing is a composite continuation token from the SDK that incorporates:
- Information from Cosmos DB's backend to resume query execution and retrieve the next page on a particular partition (the token field)
- Information on which partition the backend continuation token came from (the range field).
What you are seeing is that for the particular range the SDK is querying there were no more results.
As for why the SDK does not just give a json null value for the continuation token: The SDK has reached the end for a given partition but mstill needs to visit other partitions to know for sure that there are no more documents that match your filter / need to be returned to the client.
When the SDK is done visiting all partitions it will return a null continuation.
来源:https://stackoverflow.com/questions/51853612/null-continuation-token-in-cosmosdb