我正在尝试在文档数据库(Cosmos DB)中调用JavaScript SP,尽管我的预期记录正在文档数据库中更新,但我没有将响应返回给调用者。
控制权不会返回给调用者,也没有例外。
var response = await client.ExecuteStoredProcedureAsync<Dictionary<string, object>>(sp.SelfLink, new RequestOptions
{
PartitionKey = new PartitionKey(partitionKey),
AccessCondition = new AccessCondition()
{
Type = AccessConditionType.IfMatch
}
}, parameters);
答案 0 :(得分:0)
尝试以下操作,
private List<Dictionary<string, object>> _items { get; } = new List<Dictionary<string, object>>();
private readonly DocumentClient _client;
private readonly Uri _sprocLink;
public CosmosDBStreamPersisterBatch(DocumentClient client, Uri sprocLink)
{
_client = client;
_sprocLink = sprocLink;
}
public async Task<StoredLatency> Commit()
{
var partitionKey = _items.First()[nameof(StreamEntityBase.PartitionKey)];
var response = await _client.ExecuteStoredProcedureAsync<string>(_sprocLink,
new RequestOptions { PartitionKey = new Microsoft.Azure.Documents.PartitionKey(partitionKey) },
new { docs = _items });
return new StoredLatency() { NumItems = _items.Count, Time = StreamEntityPersisterPartition.GetStoredLatency(_items) };
}
public void AddItem(Dictionary<string, object> item)
{
_items.Add(item);
}
答案 1 :(得分:0)
请参考我的工作代码:
private static readonly string endpointUrl = "https://***.documents.azure.com:443/";
private static readonly string authorizationKey = "***";
private static readonly string databaseId = "db";
private static readonly string collectionId = "part";
private static DocumentClient client;
public static void QueryTestAsync()
{
client = new DocumentClient(new Uri(endpointUrl), authorizationKey);
var uri = UriFactory.CreateDocumentCollectionUri(databaseId, collectionId);
var requestOptions = new RequestOptions { PartitionKey = new PartitionKey("white") };
StoredProcedureResponse<string> sprocResponse = client.ExecuteStoredProcedureAsync<string>("dbs/db/colls/part/sprocs/1/", requestOptions).Result;
Console.WriteLine("Execute Output: {0}", sprocResponse.Response);
}