嗨我们在查询时遇到问题。该文档存在于数据库中。
“消息:{\”错误\“:[\”未找到资源\“]} \ r \ nActivityId: 03866338-6596-49b6-8704-1726cb373bfb,请求URI: /应用/ ab277caf-ee90-4cc3-96cb-4d4ec5ae2b13 /服务/ 17e48284-a3a0-40c5-b5ec-40bd3f207472 /分区/ 27cb7777-5add-4f72-8a73-1fc8fe34e7bf /复制/ 131603393672093060p /, RequestStats :,SDK:Microsoft.Azure.Documents.Common / 1.19.162.2“
数据库中的文档
{
"consumername": "testconsumer",
"tablename": "Table1",
"securityaccount": "v-naagga",
"logtime": "2018-01-13T21:42:21.3040338-08:00",
"securitydefinition": {
"tablename": "table1",
"ColumnList": {
"columnname": "name",
"columndatatype": "string"
},
"RowSecurity": {
"columnname": "address",
"operator": "operator",
"condition": "somecondition"
}
},
"id": "15554839-096d-4072-8f38-af2e9c64b452",
"_rid": "LmUiAONSDQQBAAAAAAAAAA==",
"_self": "dbs/LmUiAA==/colls/LmUiAONSDQQ=/docs/LmUiAONSDQQBAAAAAAAAAA==/",
"_etag": "\"00002e04-0000-0000-0000-5a5aedd60000\"",
"_attachments": "attachments/",
"_ts": 1515908566
}
以下是抛出此错误的更新方法代码
{
try
{
RequestOptions options = new RequestOptions();
options.PartitionKey = new PartitionKey(id);
options.ConsistencyLevel = ConsistencyLevel.Session;
return await client.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(DatabaseId, SecurityCollectionId, id), item,options).ConfigureAwait(false);
}
catch (Exception ex)
{
Logger.Log(ErrorLevel.Error, ex.Message);
throw ex;
}
}
答案 0 :(得分:1)
根据我的观察,我认为您的问题应该是分区键设置错误。
请参阅此official document。您需要提供分区键的值,而不是存储分区键的字段的名称。
例如,我的容器创建如下:
分区键是" name"我的收藏在这里。您可以检查收藏夹的分区键。
我的文件如下:
{
"id": "1",
"name": "jay"
}
{
"id": "2",
"name": "jay2"
}
我的partitionkey
是&#39; name&#39; ,所以我在这里有两个分区:&#39; jay&#39; 和<强>&#39; jay1&#39; 强>
所以,在这里你应该将partitionkey
属性设置为&#39; jay&#39;或者&#39; jay2&#39;,而不是&#39; name&#39;。
try
{
RequestOptions options = new RequestOptions();
options.PartitionKey = new PartitionKey("jay");
options.ConsistencyLevel = ConsistencyLevel.Session;
return await client.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(DatabaseId, SecurityCollectionId, id), item,options).ConfigureAwait(false);
}
catch (Exception ex)
{
Logger.Log(ErrorLevel.Error, ex.Message);
throw ex;
}
希望它对你有所帮助。
更新答案:
请参阅我的测试代码。
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;
using System;
using System.Linq;
namespace ConsoleApp2
{
class Program
{
private static DocumentClient client;
static string endpoint = "***";
static string key = "***";
static string database = "***";
static string collection = "***";
static void Main(string[] args)
{
client = new DocumentClient(new Uri(endpoint), key);
try
{
Sample querysample = client.CreateDocumentQuery<Sample>(
UriFactory.CreateDocumentCollectionUri(database, collection))
.Where(so => so.id == "1")
.AsEnumerable()
.First();
Console.WriteLine(querysample.tablename);
querysample.tablename = "Table2";
RequestOptions options = new RequestOptions();
options.PartitionKey = new PartitionKey("1");
options.ConsistencyLevel = ConsistencyLevel.Session;
var result = client.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(database, collection, "1"), querysample, options).Result;
}
catch (Exception ex)
{
throw ex;
}
Console.ReadLine();
}
}
public class Sample
{
public string id { get; set; }
public string tablename { get; set; }
}
}
id
是我的分区键,值为'1'
。您能否检查我们的代码之间的差异?
如有任何疑虑,请告诉我。