RU Fee for queries in DocumentDB

In the .NET library, how do I determine the RU board for a request. It returns IQueryable, and I'm not sure how to do this. Bonus points for registering the entire RU request.

Simple code, but does not return RU:

 var docs = DocumentDBRepository<CampaignMessage>.client.
         CreateDocumentQuery<CampaignMessage>(UriFactoryExtensions.CreateCollectionUri(), new FeedOptions() { MaxItemCount = -1, MaxDegreeOfParallelism = 5 }).Where(x => x.BlastKey == "abc-796").
+6
source share
1 answer

In the .NET library, how do I determine the RU board for a request. It returns IQueryable, and I'm not sure how to do this.

As a link provided by Mikhail, you need to call docs.AsDocumentQuery().ExecuteNextAsyncto get the result from the DocumentDB service, you can get RU for a request from FeedResponse<T>.RequestCharge.

RU .NET Client SDK , . , RU , , :

public static class DocumentDBExtension
{
    public static async Task<IEnumerable<TSource>> QueryWithRuLog<TSource>(this IQueryable<TSource> source)
    {
        List<TSource> items = new List<TSource>();
        double totalRuCost = 0;
        var query = source.AsDocumentQuery();
        while (query.HasMoreResults)
        {
            var result =await query.ExecuteNextAsync<TSource>();
            items.AddRange(result);
            //log RU
            totalRuCost += result.RequestCharge;
        }
        //log totalRuCost
        Console.WriteLine($"RUs cost:{totalRuCost}");
        return items;
    }
}

//Usage
var result=docs.QueryWithRuLog<CampaignMessage>();
+4

Source: https://habr.com/ru/post/1016862/


All Articles