简体   繁体   English

Azure Cosmos DB Python SDK:如何读取更改提要?

[英]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.

相关问题 Python azure SDK 的 cosmos DB 分页的 MaxItemCount 在哪里 - Where is MaxItemCount for cosmos DB pagination for Python azure SDK 如何将 Django 与 Azure Cosmos DB 连接 - How to connect Django with Azure Cosmos DB 如何使用 azure 函数覆盖 azure cosmos DB 中的文件(python) HTTP 触发器 - How to overwrite a file in azure cosmos DB using azure functions(python) HTTP trigger 如何从 Python 中的 Azure Function 调用 Cosmos DB 存储过程? - How do I call an Cosmos DB stored procedure from Azure Function in Python? 如何在 Python 中将批量数据插入 Cosmos DB? - How to insert bulk data into Cosmos DB in Python? 如何使用python更新Cosmos Db中的记录? - How To Update Record in Cosmos Db using python? 使用 python 的 azure cosmos db SQL API 地理空间数据 - Geospatial data with azure cosmos db SQL API using python 自定义应用程序的 RBAC 权限? 使用 Azure、python 和 Cosmos DB - RBAC Permissions for a Custom Application? Using Azure, python, & Cosmos DB 将 Azure Cosmos DB 图数据库转换为 python 图 object - Converting Azure Cosmos DB graph database to python graph object Azure Functions/Cosmos DB 中的 MaxItemCount - MaxItemCount in Azure Functions/Cosmos DB
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM