首页 文章

没有partitionkey的cosmosdb bulkdelete

提问于
浏览
0

我试图在cosmosdb集合上使用storedprocedure进行查询文档批量删除 . 我从这里使用了示例代码 .

https://github.com/Azure/azure-documentdb-js-server/blob/master/samples/stored-procedures/bulkDelete.js

当我尝试执行查询时,我被迫提供一个我不知道的分区键 . 我想根据不包含分区键的查询条件执行扇出删除查询 . 我可以尝试从cosmosdb集合中批量删除文档的其他方法是什么?

2 回答

  • 0

    如果注册存储过程的集合是单分区集合,则事务的范围限定为集合中的所有文档 . 如果集合是分区的,则存储过程在单个分区键的事务范围内执行 . 然后,每个存储过程执行必须包括与事务必须在其下运行的范围相对应的分区键值 .

    你可以参考上面提到here的描述 .

    当然,如果您的集合已被分区,则还需要在操作集合或文档时提供分区键 . 来自here的更多细节 .

    所以,根据你不了解分区键的情况,我建议你在执行删除时在 FeedOptions 中将 EnableCrossPartitionQuery 设置为 true . (有性能瓶颈)

    希望它能帮到你 .

  • 0

    现在,当我们从Python调用时,我们在选项中设置'EnableCrossPartitionQuery=' True' . 它仍然显示错误 . pydocumentdb.errors.HTTPFailure: Status code: 400 {"code":"BadRequest","message":"PartitionKey value must be supplied for this operation.

    这是我们使用pydocumentdb进行的python调用 .

    def exec_sp(member_number): client = document_client.DocumentClient(statics.cosmosEndpoint, {'masterKey': statics.cosmosMasterkey}) query = {'query': "select * from c where c.type='Transaction'"} options = {} options['enableCrossPartitionQuery'] = True coll_path = 'dbs/database/colls/samplecollection' sp_path = coll_path + '/sprocs/' + 'bulkdelete' result = client.ExecuteStoredProcedure(sp_path, query, options=options)

相关问题