DocumentDB替换不工作

Tri*_*des 6 azure azure-cosmosdb

我最近意识到DocumentDB通过ReplaceDocumentAsync支持独立的更新操作.

我用Replace操作替换了下面的Upsert操作.

var result = _client
    .UpsertDocumentAsync(_collectionUri, docObject)
    .Result;
Run Code Online (Sandbox Code Playgroud)

所以这是现在:

var result = _client
    .ReplaceDocumentAsnyc(_collectionUri, docObject)
    .Result;
Run Code Online (Sandbox Code Playgroud)

但是,现在我得到了例外:

Microsoft.Azure.Documents.BadRequestException:ResourceType Document是意外的.ActivityId:b1b2fd71-3029-4d0d-bd5d-87d8d0a2fc95

不知道为什么,upsert和replace具有相同的静脉,而且对象与upsert相同,所以我希望它可以毫无问题地工作.

所有帮助赞赏.

谢谢

更新:尝试使用SelfLink方法实现此功能,并且适用于替换,但自身链接不适用于Upsert.这种行为令人困惑.我不喜欢我必须使用字符串连接在代码中构建自我链接.

Lar*_*one 3

恐怕使用字符串连接构建自链接是您唯一的选择,因为ReplaceDocument(...)需要指向文档的链接。您在示例中显示了指向该集合的链接。它不会像您希望的那样吸出 ID 并找到文档。

NPM 模块documentdb-utils具有用于构建这些链接的库函数,但它只是使用字符串连接。我见过 .NET 的等效库,但我不记得在哪里。也许它在 Azure 示例中,甚至现在在 SDK 中。