首页 文章

Azure DocumentDB所有者资源不存在

提问于
浏览
6

我有相同的错误icrosoft.Azure.Documents.DocumentClientException:消息:{“错误”:[“所有者资源不存在”]},这是我的方案 . 当我将我的webapp部署到Azure并尝试从docDb获取某些文档时,它会抛出此错误 . docdb存在于azure中,包含我要查找的文档 .

奇怪的是,从我的本地机器(从VS运行),这工作正常 . 我在Azure和本地使用相同的设置 . 有人对此有所了解 .

谢谢

3 回答

  • 1

    所有者资源不存在

    当您提供错误的数据库名称时会发生 .

    例如,在使用 client.readDocument(..) 读取文档时,客户端是 DocumentClient 实例, docLink 中给出的数据库名称是错误的 .

  • 2

    我有同样的问题 . 我发现Visual Studio 2017使用我的Release配置而不是我选择的Test配置进行发布 . In my case the Release configuration had a different CosmosDB database name that doesn't exist ,当我发布到我的Azure测试服务器时导致"owner resource does not exist"错误 . 超级令人沮丧和一个可怕的错误信息 .

  • 9

    肯定这个错误似乎与读取不存在的数据库/集合/文档有关 . 对于确实存在的数据库,我得到了相同的确切错误,但是我将名称输入为小写,无论您的分区键是什么,都会出现此错误 .

    我现在能想到的最好的解决方案是包装

    var response = await client.ReadDocumentAsync(UriFactory.CreateDocumentUri(database, collection, "documentid"));
    

    打电话试试看,不是很优雅,我宁愿回复更多的细节,但这是微软的 .

    像下面这样的东西应该可以解决问题 .

    Model myDoc = null;
    
                    try
                    {
                        var response = await client.ReadDocumentAsync(UriFactory.CreateDocumentUri(database, collection, document));
                        myDoc = (Model )(dynamic)response.Resource;
                    }
                    catch { }
    
    
                    if (myDoc != null)
                    {
                       //do your work here
                    }
    

    这是为了更好地了解错误,然后创建缺少的资源,这样你就不会再得到错误了 .

    在得出这个结论之前我必须经历的一些资源:https://github.com/DamianStanger/DocumentDbDemo

    Azure DocumentDB Read Document Resource Not Found

相关问题