DarkW1nter
DarkW1nter

Reputation: 2851

return id of newly created document in DocumentDB within .NET Core

I am using the following to create a DocumentDB document, how can I ament it to return the guid id of the document that gets created?

            _logger.LogInformation("creating document");
            Uri uri = UriFactory.CreateDocumentCollectionUri(DatabaseId, CollectionId);
            await client.CreateDocumentAsync(uri, doc);

Upvotes: 2

Views: 363

Answers (1)

Sergey Berezovskiy
Sergey Berezovskiy

Reputation: 236268

Simply read id value from the document after saving it:

 await client.CreateDocumentAsync(uri, doc);
 _logger.LogInformation($"created document {doc.Id}");

Upvotes: 2

Related Questions