golang / cosmosdb分页
我正在尝试使用 cosmosapi软件包),我正在尝试实现分页。 azure文档令牌永远不会到期,我正在尝试理解它的语义。
在 cosmos db持续代币如何工作?达成协议达成协议。
在服务第一页后创建的文档可以观察到 后续页面
我试图通过从Golang申请的一些实验中进行一些实验来验证这一点,而某些事情并非完全正确。作为一个非常高的示例,如果我们将三个记录插入cosmosdb:
Insert record #1
Insert record #2
Insert record #3
然后,如果我们尝试从表(query = query = select * select * select * select * by c.datefield desc by c.datefield desc)使用此选项:
opts := cosmosapi.QueryDocumentsOptions{
IsQuery: true,
ContentType: cosmosapi.QUERY_CONTENT_TYPE,
ConsistencyLevel: cosmosapi.ConsistencyLevelStrong,
Continuation: "",
PartitionKeyValue: partitionKeyValue,
MaxItemCount: 2,
}
它返回:
record #1
record #2
continuation token = "cont-token-1"
现在再次选择使用相同的选项,但持续令牌不同:
opts := cosmosapi.QueryDocumentsOptions{
IsQuery: true,
ContentType: cosmosapi.QUERY_CONTENT_TYPE,
ConsistencyLevel: cosmosapi.ConsistencyLevelStrong,
Continuation: "cont-token-1",
PartitionKeyValue: partitionKeyValue,
MaxItemCount: 2,
}
它返回
record #3
相当合乎逻辑的。 现在,当我尝试插入记录#4时,并且在记录#3之后立即插入它,然后尝试使用“ cont-token-1”获取记录,记录#4并未显示。它只有在我使用空的Opts.Contination字段再次选择延续令牌时才显示出来。
如果我尝试使用空的持续令牌选择选择,则它将获取记录#1并记录#2,并导致一个新的令牌,该令牌获取记录#3和记录#4。
这是预期的行为吗?还是我错过了什么? 从我的理解中,它应该显示出来。延续令牌就像书签一样,即使使用相同的延续令牌,也应该看到结果。
I'm trying to implement pagination while selecting records from CosmosDB using cosmosapi package.
The azure documentation states that continuation tokens never expire and I'm trying to understand the semantics of that.
In How does Cosmos DB Continuation Token work? there is an agreement that
Documents created after serving the first page are observable on
subsequent pages
I tried to validate that point by running some experiments from a golang applicaiton, and something is not quite right. As a very high level example, if we insert three records to CosmosDB:
Insert record #1
Insert record #2
Insert record #3
Then if we try to select from the table (query = SELECT * FROM c ORDER BY c.dateField DESC) using this options:
opts := cosmosapi.QueryDocumentsOptions{
IsQuery: true,
ContentType: cosmosapi.QUERY_CONTENT_TYPE,
ConsistencyLevel: cosmosapi.ConsistencyLevelStrong,
Continuation: "",
PartitionKeyValue: partitionKeyValue,
MaxItemCount: 2,
}
it returns:
record #1
record #2
continuation token = "cont-token-1"
Now when selecting again with the same options, but different continuation token:
opts := cosmosapi.QueryDocumentsOptions{
IsQuery: true,
ContentType: cosmosapi.QUERY_CONTENT_TYPE,
ConsistencyLevel: cosmosapi.ConsistencyLevelStrong,
Continuation: "cont-token-1",
PartitionKeyValue: partitionKeyValue,
MaxItemCount: 2,
}
It returns
record #3
Which is fairly logical.
Now when I try to insert record #4, and it gets inserted right after record #3, and try to fetch using "cont-token-1", record #4 does not show up. It only shows up when I regenerate the continuation tokens by selecting again using an empty opts.Continuation field.
If I try to select using an empty continuation token, then it fetches record #1 and record #2, and leads to a new token that fetches record #3 and record #4.
Is this the expected behavior? Or am I missing anything?
From my understanding, it should show up. The continuation token is like a bookmark, and it should see the results even when using the same continuation token.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
连续令牌只能与完全相同的查询使用,并且每次都会返回完全相同的答案,无论您如何更改基础数据,如果您的基础数据以这种方式更改,则需要获得新的令牌被包括在第一个答案中。
A continuation token can only be used with the exact same query and will return the exact same answer every time, regardless of how you change the underlying data, you need to get a new token if your underlying data changes in such a way that would have been included in the first answer.