public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, [CosmosDB(ConnectionStringSetting = "cosmosConnectionString")] IDocumentClient documentClient, ILogger log) { var database = Environment.GetEnvironmentVariable("cosmosDatabaseName"); var container = Environment.GetEnvironmentVariable("cosmosContainerName"); var containerUri = UriFactory.CreateDocumentCollectionUri(database, container); string continuationToken = null; var documents = new List <Product>(); do { var feed = await documentClient.ReadDocumentFeedAsync(containerUri, new FeedOptions { MaxItemCount = 25, RequestContinuation = continuationToken }); continuationToken = feed.ResponseContinuation; foreach (var doc in feed) { var docString = doc.ToString(); var product = JsonConvert.DeserializeObject <Product>(docString); documents.Add(product); } } while (continuationToken != null); return(new OkObjectResult(documents)); }
public async Task <List <Document> > ReadAllDocumentsInCollection(int maxItemCount = 10, CancellationToken cancellationToken = default(CancellationToken)) { var result = new List <Document>(); string continuationToken = null; var options = new FeedOptions { MaxItemCount = maxItemCount, RequestContinuation = continuationToken, EnableCrossPartitionQuery = true }; do { var feed = await _documentClient.ReadDocumentFeedAsync( UriFactory.CreateDocumentCollectionUri(_databaseName, _collectionName), options); continuationToken = feed.ResponseContinuation; result.AddRange(from Document document in feed select document); } while (continuationToken != null); return(result); }