[英]How to update a property in an Entity in Cosmos table API using Python
我在 CosmosDB 中有下表。
PartitionKey Rowkey Group Salary
John HR A 100000
Mark DOC B 200000
我想更新第一個實體中的 Salary 屬性。 當我嘗試更新第一個實體中的 salary 屬性時,整個實體被替換而不是更新 salary 屬性。
誰能告訴我如何更新 CosmosDB 表 API 中實體的屬性。
from azure.data.tables import TableServiceClient
from datetime import datetime
my_entity = {
"PartitionKey" : "John",
"RowKey" : "HR",
"Group": "A",
"Salary": 100000
}
table_service_client = TableServiceClient.from_connection_string(conn_str="")
table_client = table_service_client.get_table_client(table_name="my_table")
entity = table_client.create_entity(entity=my_entity)
created = table.get_entity(partition_key=my_entity["PartitionKey"], row_key=my_entity["RowKey"])
created["Salary"] = "200"
table.update_entity(mode=UpdateMode.REPLACE, entity=created)
請嘗試更改以下代碼行:
created = table.get_entity(partition_key=my_entity["PartitionKey"], row_key=my_entity["RowKey"])
created["Salary"] = "200"
table.update_entity(mode=UpdateMode.REPLACE, entity=created)
和
created = table_client.get_entity(partition_key=my_entity["PartitionKey"], row_key=my_entity["RowKey"])
created["Salary"] = "200"
table_client.update_entity(mode=UpdateMode.MERGE, entity=created)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.