使用不带分区键规范的查询从Cosmos删除文档 [英] Delete Documents from Cosmos using Query without Partition Key Specification

查看:123
本文介绍了使用不带分区键规范的查询从Cosmos删除文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个存储过程,以通过使用查询来删除Cosmos Db中的文档.查询返回文档后,我希望删除所有文档.

I am trying to create a stored procedure to delete documents in Cosmos Db by using a query. Once the query returns the documents, I would like all the documents to be deleted.

我尝试使用此网站,但这需要放置一个分区密钥.我的Cosmos集合每个文档都有一个单独的分区键,因此无法使用

I tried using the script from this website but this requires putting one partition key. My Cosmos collection has a separate partition key per document so it will not work

这是我要运行的查询示例

This is an example of a query I would like to run

SELECT c.currentTime, c.pastTime 
FROM C 
WHERE c.currentTime < c.pastTime

如果满意,我想从该查询中删除所有结果.

If that satisfies, I would like to delete all the results from that query.

有没有一种方法可以创建存储的proc或修改提供的网站中的proc,以便它遍历所有集合而不是指定一个分区键?

Is there a way create a stored proc or modify the one in the website provided so it loops through all the collection instead of specifying one partition key?

推荐答案

有没有一种方法可以创建存储的proc或修改网站中的proc 提供,因此它遍历所有集合而不是指定 一个分区键?

Is there a way create a stored proc or modify the one in the website provided so it loops through all the collection instead of specifying one partition key?

快速答案是否",请参阅一些官方声明:

The quick answer is no,please see some official statements:

1.我之前回答过类似的情况,他们都希望在执行SP时避免这样的分区键要求.但是,这是不可避免的.

1.I answered similar cases before, they all want to avoid such partition key requirement when executing SP.However,it can't be avoided.

Azure Cosmos DB要求存储分区键程序

在没有PartitionKey的情况下Cosmos DB存储过程无法执行

如果集合所存储的过程被注册为一个 单分区集合,则事务范围为所有 馆藏内的文件.如果集合已分区, 然后在一个存储区的事务范围内执行存储过程 单分区键.然后必须执行每个存储过程 包括与范围相对应的分区键值 交易必须在此之下进行.

If the collection the stored procedure is registered against is a single-partition collection, then the transaction is scoped to all the documents within the collection. If the collection is partitioned, then stored procedures are executed in the transaction scope of a single partition key. Each stored procedure execution must then include a partition key value corresponding to the scope the transaction must run under.

2.上面的语句和链接已修改为新的

2.Above statement and link have been modified into below new document:

3.您可以按照官方建议来了解Bulk Executor Lib SDK的想法.我在此源代码中找到了BulkDelete功能,请尝试一下.

3.You could follow official suggestion to get an idea of Bulk Executor Lib SDK. I found BulkDelete feature in this source code,please try it.

这篇关于使用不带分区键规范的查询从Cosmos删除文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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