简体   繁体   中英

Get document collection in azure db?

Using Azure DB in a cloud function I have the following:

 var client = new DocumentClient(new Uri(endPoint), primaryKey);
            var collUrl = UriFactory.CreateDocumentCollectionUri("id", "course");

            var doc = (await client.ReadDocumentCollectionAsync(collUrl)).Resource;

doc is a DocumentCollection but it doesn't look like there's any way to access an enumerator or something to view the contents so I might be in the wrong place?

doc is a DocumentCollection

As you metioned that doc is a documentCollection, more details please refer to DocumentClient.ReadDocumentCollectionAsync Method is used to read a DocumentCollection from the Azure Cosmos DB service as an asynchronous operation.

but it doesn't look like there's any way to access an enumerator or something to view the contents so I might be in the wrong place?

If you want to list the documents in the collection, we could use DocumentClient.CreateDocumentQuery Method to do that. We also could get the demo code from github

   var doc = (await client.ReadDocumentCollectionAsync(collUrl)).Resource;
   var documents = client.CreateDocumentQuery(doc.SelfLink).AsEnumerable().ToList();

在此处输入图片说明

As far as I can tell there is no iterator on the collection itself. You can, however, create a query on the collection like this:

var docs = client.CreateDocumentQuery(collUrl);
foreach (var document in docs)
{
    // Do stuff with your document
}

Please note there are a lot of overloads for CreateDocumentQuery at this time.

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