2

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?

Satyaray Singh
  • 267
  • 3
  • 11

1 Answers1

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.

Jay Gong
  • 23,163
  • 2
  • 27
  • 32
  • did not find any overridden method for ExecuteStoredProcedureAsync which take FeedOptions. do I need to pass the EnableCrossPartitionQuery to true in the stored procedure requestOptions? @jay Gong – Satyaray Singh Apr 27 '18 at 05:14
  • @SatyaraySingh no no, EnableCrossPartitionQuery is one property in FeedOptions,not RequestOptions. So,you have to provide partition key with executing stored procedure anyway. – Jay Gong Apr 27 '18 at 05:29
  • there are 4 override methods ExecuteStoredProcedureAsync in DocumentClient class to Execute the stored procedure but none of them have FeedOptions as parameters. is that Simply means I can't do that in store procedure? @jay Gong – Satyaray Singh Apr 27 '18 at 05:55
  • @SatyaraySingh Yes. you don't have any routes to get the partition key? – Jay Gong Apr 27 '18 at 06:04
  • the Documents which I'm trying to fetch all have a different partition key. I think I need to fetch all the document in code then update it after that I will save it individually. @jay Gong – Satyaray Singh Apr 27 '18 at 06:22
  • @SatyaraySingh Let's talk in this chat room:https://chat.stackoverflow.com/rooms/169914/jay-satyaray-singh – Jay Gong Apr 27 '18 at 06:30
  • @SatyaraySingh Sorry for the delay message ,please check the chat room again .Thx. – Jay Gong Apr 27 '18 at 08:03
  • @JayGong is there a way to create unpartitioned collection? and btw the link is not valid any more:( – fascynacja Apr 01 '20 at 06:54
  • 1
    @fascynacja Surely,you have to create unpartitioned collection by sdk,not on the portal. I searched just now,but i can't find any statement at the creation tag of cosmos db on the portal. I remember there is a suggestion for you over there. Anyway , do it in sdk. Don't set partition key when you create collection in sdk. – Jay Gong Apr 01 '20 at 06:58