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

Che*_*uru 5 azure nosql azure-cosmosdb

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

系统中不存在具有指定标识的实体

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

代码如下后面的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);
    }
}
Run Code Online (Sandbox Code Playgroud)

存储过程如下

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.');
}
Run Code Online (Sandbox Code Playgroud)

在我的localhost它工作正常但网站发布到azure网络应用程序和运行我正在上面的错误

Mur*_*oft 14

我只花了几个小时对此进行故障排除,结果发现我已经将我的实例防火墙到了我无法在本地连接的地方.请记住,即使您没有通过API/C#客户端直接访问,Azure门户文档查询显然仍然有效.

尝试设置防火墙以允许所有网络临时检查访问权限.

CosmosDB防火墙设置


Mid*_*mmy 0

我会在门户中检查“GetMemberbyId”是您尝试运行它的集合的存储过程的名称。存储过程可能位于不同的集合中,或者存储过程被命名为其他名称。

如果一切顺利的话..我在使用 __.filter() 查询服务器上文档的方式方面运气更好。请参阅: http: //azure.github.io/azure-documentdb-js-server/