我正在按照下面的代码使用DeleteDocumentAsync。
public static void DeleteErrorLog(List<string> LogID, string collectionName)
{
FeedOptions queryOptions = new FeedOptions { EnableCrossPartitionQuery = true };
try
{
//getting resource id for a document with given logid
var db = client.CreateDatabaseQuery().Where(x => x.Id == databaseName).ToList().First();
var coll = client.CreateDocumentCollectionQuery(db.SelfLink).Where(x => x.Id == collectionName).ToList().First();
var docs = client.CreateDocumentQuery(coll.SelfLink, queryOptions).Where(x => x.Id == LogID[0]).AsEnumerable().Single();
var collectionUri = UriFactory.CreateDocumentUri(databaseName, collectionName, docs.ResourceId);
client.DeleteDocumentAsync(collectionUri);
}
catch (Exception) { throw; }
}
每个值都正确填充,我要删除的文档仍无法删除吗?任何帮助是极大的赞赏
您可能缺少用于删除操作的PartitionKey:
var documentUri = UriFactory.CreateDocumentUri(databaseName, collectionName, LogID[0]);
client.DeleteDocumentAsync(documentUri, new RequestOptions(){PartitionKey=new PartitionKey(LogID[0])}).GetAwaiter().GetResult();
另外,如果您已经知道ID(在您的情况下为)LogID[0]
,则不需要查询。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句