CosmosDB中FeedOptions.RequestContinuation令牌的唯一定义解析
Great question—let’s break down exactly what makes up Cosmos DB’s FeedOptions.RequestContinuation token, and why you’re seeing different values even when recreating seemingly identical data.
First, it’s important to note that the RequestContinuation token is an opaque, base64-encoded string that Cosmos DB uses to track the exact position of your query’s last returned result. Its uniqueness depends on several core components:
Key Components of the RequestContinuation Token
- Document Resource ID (
_rid): Every document in Cosmos DB gets a unique, system-generated_ridproperty at creation time—this is non-negotiable, even if all other document fields are identical. The continuation token includes the_ridof the last document returned in the current page. Since you’re deleting and recreating documents, their_ridvalues will be completely different each time, which directly changes the token. - Partition Key Range Context: If you’re using a partitioned collection, the token encodes information about the specific partition key range your query is scanning. Even if your query targets the same logical partition, internal range identifiers might tie to the current state of the collection (though this is less likely to change in your scenario).
- Query Execution State: This includes specifics of your query like
MaxItemCount, filter conditions, sort order, and the last evaluated value of your sort key (if you’re sorting). While your query parameters are the same, the actual last document’s metadata (like_ridor sort field values tied to the new document) will differ, altering this state. - Collection & System Metadata: The token also includes identifiers tied to the target collection (its own
_rid) and internal system context to ensure the token is only valid for the specific collection and query session it was generated for.
Why Your Tokens Are Different
In your test scenario, even though your POCO data is identical, the auto-generated system properties (especially _rid) of the recreated documents are entirely new. When you run the query again, the continuation token references the _rid of the last document from the new dataset—this is a different value than the first run, so the encoded token string will not match.
A quick note: Microsoft explicitly recommends treating the RequestContinuation token as an opaque value (don’t try to parse or modify it directly) since its internal format can change with Cosmos DB updates. But understanding its core components helps explain why identical-looking queries can produce different tokens.
内容的提问来源于stack exchange,提问作者Octopus

