c# - 返回 .NET Core 中 DocumentDB 中新创建文档的 id

标签 c# asp.net-core-webapi document-database

我正在使用以下命令创建 DocumentDB 文档,如何修改它以返回所创建文档的 guid id?

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

最佳答案

保存后只需从文档中读取 id 值:

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

关于c# - 返回 .NET Core 中 DocumentDB 中新创建文档的 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47184132/

相关文章:

mongodb - 多列索引的最佳数据库?

php - 存储html内容的文档数据库

c# - 如何在 GDI+ 中对具有真实形状测量值(英寸)的旋转形状进行 HitTest ?

c# - 使用字符串列表过滤 Entity Framework

c# - 为什么 Asp.net core Web API 2.0 返回 Http Error 500

asp.net-core-mvc - 使用 openIdDict 我们是否必须在 Startup.cs 中包含 'UseIdentity()' ?

azure-cosmosdb - 根据 Azure Cosmos DB 中文档的属性获取最新文档

c# - VNC如何连续重绘窗口?

c# - 语言转换测试

authentication - 在 JWT 中更新/更改角色声明(或任何其他声明)