[英]Azure Cosmos DB Python SDK : How to read change feed?
This question may be trivial but I cannot figure out how to read change feed using PyDocument DB and the documentation isn't very helpful. 这个问题可能很琐碎,但我无法弄清楚如何使用PyDocument DB读取更改摘要,并且该文档不是很有帮助。
Until now, I've been using native Cosmos DB connector and there I could just set these parameters inside of the config : 到目前为止,我一直在使用本机的Cosmos DB连接器,并且可以在config中设置这些参数:
"ReadChangeFeed" :
"ChangeFeedQueryName" :
"ChangeFeedStartFromTheBeginning" :
"ChangeFeedUseNextToken" :
"RollingChangeFeed" :
But the very same options won't work with the Python SDK so I cannot do something like this. 但是,完全相同的选项不适用于Python SDK,因此我无法执行此类操作。
query = client.QueryDocuments(collLink, querystr, options= { 'enableCrossPartitionQuery': True, "ReadChangeFeed" :True})
# Push into list `elements`
elements = list(query)
I have tried to find some samples but unsuccessfully. 我试图找到一些样本,但是没有成功。
Thank you in advance! 先感谢您!
Please check our official samples here to read the Change Feed, you can use the QueryItemsChangeFeed
method: https://github.com/Azure/azure-cosmos-python/tree/master/samples/ChangeFeedManagement 请在此处查看我们的官方样本以阅读变更
QueryItemsChangeFeed
,您可以使用QueryItemsChangeFeed
方法: https : //github.com/Azure/azure-cosmos-python/tree/master/samples/ChangeFeedManagement
Here is a snippet: 这是一个片段:
options = {}
options["startFromBeginning"] = True
response = client.QueryItemsChangeFeed(collection_link, options)
for doc in response:
print(doc)
Where client
is an instance of a Cosmos DB client and collection_link
is the name based link to the Collection you want to read, for example dbs/<your-db>/colls/<your-collection>
. 其中
client
是Cosmos DB Client的实例,而collection_link
是指向您要读取的Collection的基于名称的链接,例如dbs/<your-db>/colls/<your-collection>
。
startFromBeginning
is a flag that will start to read from the beginning of the history of the collection, optionally (also included in the Github sample) is the use of startTime
. startFromBeginning
是一个标志,将从集合的历史记录开始读取,可选(也包括在Github示例中)是使用startTime
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.