如何将多个输入传递给cosmosdb存储过程

时间:2019-03-18 18:14:42

标签: azure-cosmosdb

MS上有一些很棒的示例,这些示例涉及批量导入和批量删除,我已经能够使用python来使它们同时工作。例如 dbclient.ExecuteStoredProcedure(parameterscolllink + '/sprocs/bulkImport', dumps(adddat), { 'partitionKey' : 0}))

然后在我的SPROC中将字符串反序列化为一个数组:if (typeof items === "string") items = JSON.parse(items)

但是,该MS页面中的示例之一是SPROC,用于交换幻想足球运动员,并且SPROC具有两个不同的变量: function tradePlayers(playerId1, playerId2)

python如何执行SPROC并传递2个变量?

1 个答案:

答案 0 :(得分:0)

您可以将多个参数作为数组传递给cosmos db存储过程。

import azure.cosmos.cosmos_client as cosmos_client

endpoint = "https://***.documents.azure.com:443/";
primaryKey = "***";

client = cosmos_client.CosmosClient(url_connection=endpoint, auth={'masterKey': primaryKey})

sproc_link = "dbs/db/colls/jay/sprocs/test"

params = ["a","b"];

str = client.ExecuteStoredProcedure(sproc_link, params)
print(str);

此外,您可以参考以下示例:https://gist.github.com/sjwaight/3c5cf9503f588b190b5ff02bb79f07f0


更新答案:

对不起,很晚。您可以使用.net代码(请参见案例:Unable to Execute procedure with multiple parameters)来调用这种类型的代码:

var email = "xxxxx";
var password = "xxxx";
var response = await client.ExecuteStoredProcedureAsync<string>(storedProcedurelink, new RequestOptions { PartitionKey = new PartitionKey(partitionKey) },email,password);

我检查ExecuteStoredProcedureAsync的构造函数,它接受动态数组。

enter image description here

对于python代码,找不到这种调用方法。您仍然需要按照上述示例代码将参数传递到列表中。

enter image description here