Cosmos DB Stored procedure did not execute without PartitionKey

久未见 提交于 2020-04-16 05:21:01

问题


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);

while using the other method

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

in this method, I have Pass the PartitionKey as

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

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");

        }
    });
}

}

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


回答1:


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.

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?

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

Hope it helps you.



来源:https://stackoverflow.com/questions/50044575/cosmos-db-stored-procedure-did-not-execute-without-partitionkey

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!