azure - DocumentDB/CosmosDB - 系统中不存在具有指定 ID 的实体

标签 azure azure-cosmosdb nosql

我尝试从我的 asp.net 网站连接 documentdb,但收到此错误。

系统中不存在指定id的实体

DocumentClientException:系统中不存在具有指定 ID 的实体

代码如下,在aspx代码后面

protected async void Page_Load(object sender, EventArgs e)
{
    Response.Write("Page Load<br/>");
    await GetData();
}

public async Task GetData()
{
    try
    {
        Response.Write("<br/> Get Data function Start<br/><br/>");
        using (var client = new DocumentClient(new Uri(ConfigurationManager.AppSettings["endpoint"]), ConfigurationManager.AppSettings["authKey"]))
        {
            //await client.OpenAsync();
            RequestOptions reqOpt = new RequestOptions { PartitionKey = new PartitionKey(209) };
            var parameters = new dynamic[] { 1 };
            StoredProcedureResponse<object> result = await client.ExecuteStoredProcedureAsync<object>(
                UriFactory.CreateStoredProcedureUri(ConfigurationManager.AppSettings["database"], ConfigurationManager.AppSettings["pcsd"], "GetMemberbyId"), reqOpt, parameters);
            Response.Write(result.Response.ToString());
        }
        Response.Write("<br/><br/> Get Data function End");
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message);
    }
}

存储过程如下

function GetMemberbyId(memId) {
    var collection = getContext().getCollection();

    //return getContext().getResponse().setBody('no docs found');
    // Query documents and take 1st item.
    var isAccepted = collection.queryDocuments(
        collection.getSelfLink(),
        'SELECT * FROM root m where m.memberId='+memId,
        function (err, feed, options) {
            if (err) throw err;

            // Check the feed and if empty, set the body to 'no docs found', 
            // else take 1st element from feed
            if (!feed || !feed.length) getContext().getResponse().setBody('no docs found');
            else getContext().getResponse().setBody(feed);
        });

    if (!isAccepted) throw new Error('The query was not accepted by the server.');
}

在我的本地主机中,它工作正常,但网站发布到 azure 网络应用程序并运行时,我遇到了上述错误

最佳答案

我刚刚花了几个小时对此进行故障排除,却发现我已将实例防火墙设置到无法本地连接的程度。请记住,即使您无法通过 API/C# 客户端直接访问,Azure 门户文档查询显然仍然可以工作。

尝试设置防火墙以允许所有网络暂时检查访问。

CosmosDB Firewall Settings

关于azure - DocumentDB/CosmosDB - 系统中不存在具有指定 ID 的实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43723470/

相关文章:

java - Java junits 中的模拟 CosmosClient

azure-cosmosdb - 唯一 ID 是 CosmosDB 的最佳分区键

C#:如何以编程方式扩展现有 DocumentDB 集合的定价层?

node.js - 如何使用 google 数据存储(在 javascript 中)创建模式?

android - Parse.com 相当于 SQL 连接

java - 使用 java 从 Azure 存储获取文档/word 文件内容。

Azure 中的 ASP.NET Core 环境变量

azure-cosmosdb - 在 CosmosDB 中使用 PartitionKey 创建集合

javascript - 使用 JavaScript,我如何执行将返回多个值的二进制搜索?

Azure 扩展事件目标文件