无法从documentdb中的分区集合中删除文档 [英] unable to delete document from a partitioned collection in documentdb

查看:96
本文介绍了无法从documentdb中的分区集合中删除文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在azure cosmos中使用分区集合
db 。我将文档插入到集合中。我正在尝试使用以下代码删除文档,但它不会被删除。也不会抛出
任何错误。我缺少什么?

internal static bool DeleteDocumentUnderPartition(AzureDocumentDbCollectionKind collectionKind, string partitionKey, string id)
        {
            var doc = DocumentClient.CreateDocumentQuery(GetCollectionLink(collectionKind), new FeedOptions
            {
                PartitionKey = new PartitionKey(partitionKey)
            }).AsEnumerable().FirstOrDefault(x => x.Id.Equals(id));
            DocumentClient.DeleteDocumentAsync(doc.SelfLink);            
            return true;
        }


但是,从另一个集合(非分区集合)中删除文档对我有用。任何帮助将不胜感激。



However, deleting a document from another collection (non-partitioned collection) works for me. Any help would be greatly appreciated.


推荐答案

取决于是否使用分区您可以执行以下操作:

Depending on if partition is used or not you can do following:

如果使用分区:

var book = await this.m_Client.DeleteDocumentAsync(docUri,new RequestOptions {PartitionKey = new PartitionKey(1)});

var book = await this.m_Client.DeleteDocumentAsync(docUri , new RequestOptions { PartitionKey = new PartitionKey(1) });

如果不使用分区:

var book = await this.m_Client.DeleteDocumentAsync(docUri);

var book = await this.m_Client.DeleteDocumentAsync(docUri);

如果在未设置分区的情况下提供分区键,则会出现错误。

If you provide partition key if partition is not set, you will get an error.

       

       


这篇关于无法从documentdb中的分区集合中删除文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆