简体   繁体   中英

C# Azure Cosmos DB - How to select large amount of data (~100,000 documents)

I have a Cosmos DB which I need to query 100 000 individual documents, using C#. This will be to populate a grid (with paging obviously). I have done a lot of searching but only seem to find the use of a FeedIterator to query data.

Currently I'm using this code to query my test data:

using (var appsIterator = _container.GetItemQueryIterator<SensorMaster>(query))
        {
            Console.WriteLine("\t\t\t\tID\tName\tUnitID\tPoints");
            while (appsIterator.HasMoreResults)
            {
                var apps = await appsIterator.ReadNextAsync();
                foreach (var item in apps)
                {
                    count++;
                    Console.WriteLine($"{item.ID}\t{item.Name}\t{item.UnitID}\t{item.Points}");
                }
                charge += apps.RequestCharge;
            }
            Console.WriteLine($"Total charge: {charge}");
        }

This selects ~3900 records but takes around 45 seconds to do this. Is there a better way to select a large number of documents/records?

For very large queries where you want to page the results, use the continuation token. You can get more information and learn how to use here, Pagination in Azure Cosmos DB .

It is MaxItemCount you want to focus on, not MaxPageSize.

As an aside, paging 100K records to a user is a strange use-case. I don't think I can recall a time where someone wanted to scroll through 100K items.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM