没有PartitionKey,Cosmos DB存储过程无法执行 [英] Cosmos DB Stored procedure did not execute without PartitionKey

查看:65
本文介绍了没有PartitionKey,Cosmos DB存储过程无法执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有PartitionKey的集合.我有一个存储过程,该存储过程接受查询作为参数.在此存储过程中,我正在获取一些文档以进行更新,但是在获取文档时显示了一条错误消息,当我使用方法

I have a collection which has PartitionKey.i have a made a stored procedure which accepts query as a parameter. in this stored procedure, I'm fetching some documents to update but while fetching it shows an error saying provide PartitionKey when I use the method

public Task<StoredProcedureResponse<TValue>> ExecuteStoredProcedureAsync<TValue>(Uri storedProcedureUri, [Dynamic(new[] { false, true })] params dynamic[] procedureParams);

同时使用另一种方法

public Task<StoredProcedureResponse<TValue>> ExecuteStoredProcedureAsync<TValue>(string storedProcedureLink, RequestOptions options, [Dynamic(new[] { false, true })] params dynamic[] procedureParams);

在这种方法中,我将PartitionKey传递为

in this method, I have Pass the PartitionKey as

new RequestOptions { PartitionKey = new PartitionKey(Undefined.Value)

在存储过程中使用此RequestOptions时,未提取文档.

while using this RequestOptions in the Stored Procedure no Document is Fetch.

function ABC(query) {
var collection = getContext().getCollection();
var collectionLink = collection.getSelfLink();
var response = getContext().getResponse();
// Validate input.
if (!query) throw new Error("The query is undefined or null.");

tryQueryAndDelete();

function tryQueryAndDelete(continuation) {
    var requestOptions = { continuation: continuation };

    var isAccepted = collection.queryDocuments(collectionLink, query, requestOptions, function (err, retrievedDocs, responseOptions) {
        if (err) throw err;

        if (retrievedDocs.length > 0) {
           console.log("Doc Found");
        } else {
           console.log("Doc not Found");

        }
    });
}

}

有没有可以让我获取文件而无需传递PartitionKey的信息?

is there anyway so that I can fetch the documents without passing the PartitionKey?

推荐答案

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

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.

您可以参考上面提到的

You could refer to the description above which mentioned here.

通过将分区键设置为Undefined.Value来逃避上述规则是不可能的.在分区集合中执行存储过程时,必须提供分区键.

It's impossible to escape the above rule by setting the partition-key to Undefined.Value. You must provide the partition key when you execute stored procedure in partitioned collection.

仍然存在,以便我可以获取文档而无需通过 分区键?

is there anyway so that I can fetch the documents without passing the PartitionKey?

执行查询sql时,可以在FeedOptions参数中将EnableCrossPartitionQuery设置为true.(存在性能瓶颈).

You could set EnableCrossPartitionQuery to true in FeedOptions parameter when executing query sql.(has performance bottleneck).

希望它对您有帮助.

这篇关于没有PartitionKey,Cosmos DB存储过程无法执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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