![](/img/trans.png)
[英]I want to calculate the json file before post to Cosmos db. cosmos will allow max 2mb file size. How it possible in c#?
[英]c# Cosmos Db check if file exists before creating
我有这个方法:
public async Task SaveAsync(IEnumerable<JObject> models)
{
foreach (var document in models)
{
var collectionLink = UriFactory.CreateDocumentCollectionUri(_databaseName, _collectionName);
await _client.CreateDocumentAsync(collectionLink, document);
}
}
一次创建多个文档时这很好,但是如果我有一个文档与数据库中已有的文档具有相同的 ID,我会收到一个错误:
系统中已存在具有指定 id 的实体。
因为文档实际上是不同的,我不确定我是否可以检查它是否已经存在。
有没有办法用新实体替换现有实体?
您可以使用DocumentClient.UpsertDocumentAsync而不是 CreateDocumentAsync 来创建新文档或更新现有文档,例如:
await _client.UpsertDocumentAsync(collectionLink, document);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.