1
votes

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
Hi,any updates now?Jay Gong
As per ur suggestion in the chat, I have to fetch all the documents, update the Properties then save it again each documents partition key and it works in this way.@JayGongSatyaray Singh
Great! You could mark the answer for others' reference. ThxJay Gong

1 Answers

1
votes

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.