Azure-docs: PartitionKey value must be supplied for this operation.

Created on 30 Jan 2019  Â·  10Comments  Â·  Source: MicrosoftDocs/azure-docs

I was to able to see the list of items in the browser but I get the following error when I try to click on "Details", "Edit" or "Delete":
PartitionKey value must be supplied for this operation.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: PartitionKey value must be supplied for this operation.
Source Error:
Line 23: try
Line 24: {
Line 25: Document document =
Line 26: await client.ReadDocumentAsync(UriFactory.CreateDocumentUri(DatabaseId, CollectionId, id));
Line 27: return (T)(dynamic)document;
Source File: ...\src\DocumentDBRepository.cs Line: 25

Following the instructions I used category as PartitionKey and I don't have the chance to change the size of the database.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

assigned-to-author cosmos-dsvc doc-bug triaged

Most helpful comment

You can get above to work, if you fix 2 errors:
1) The "Partition Key" must be "/category" and not "/userid" - the latter does not make sense in this example.
2) Change following line

await client.ReadDocumentAsync(UriFactory.CreateDocumentUri(DatabaseId, CollectionId, id));

to

await client.ReadDocumentAsync(UriFactory.CreateDocumentUri(DatabaseId, CollectionId, id),new RequestOptions { PartitionKey = new PartitionKey(category) });

All 10 comments

@noelram Thank you for this detailed feedback. I believe this is likely a product bug but need some additional details to understand more clearly. When you create a document in Cosmos DB with the Web App (tutorial) via the SQL API and then use the Query Explorer interface via the Azure Portal you encounter the exception stated (in the description of this issue) when attempting either of the actions: "Details", "Edit" or "Delete". Can you please provide the steps to reproduce this?

No really, I can follow this quickstart until the "Run the web app" step when it crashes when I click "Edit", "Details" or "Delete" as described.

@noelram This tutorial likely needs to be updated given the partition key requirement. Thank you for the additional details. I am going to assign to the content author to evaluate and update as appropriate.

@SnehaGunda This tutorial is not successful given the product change requiring partition key configuration. Please let me know if you need additional details.

You can get above to work, if you fix 2 errors:
1) The "Partition Key" must be "/category" and not "/userid" - the latter does not make sense in this example.
2) Change following line

await client.ReadDocumentAsync(UriFactory.CreateDocumentUri(DatabaseId, CollectionId, id));

to

await client.ReadDocumentAsync(UriFactory.CreateDocumentUri(DatabaseId, CollectionId, id),new RequestOptions { PartitionKey = new PartitionKey(category) });

@noelram @corneliussens Thanks for your feedback and the suggestions. Apologies for the delay in responding to this issue. I am working on fixing the sample and the doc.

@noelram @corneliussens the above PR's should fix these issue, they are still under review by out PM team. The content will be live in a couple of days. We will now close this issue if you don't have further questions.

please-close

Hi @SnehaGunda ,
The MR is still open. So the sample still holds the old snippet and not updated with @corneliussens stated modification - https://github.com/Azure-Samples/documentdb-dotnet-todo-app/blob/master/src/DocumentDBRepository.cs

@SnehaGunda,
When would the new guidance be updated on the official docs?

@corneliussens Hi, what does the new parameter category stand for?
For example, my partition key is based on multiply property and I set it as '/uid/roleid/departmentid' when migrate my data to cosmos db, I tried with the new solution and want to get one single document for my User item based on my uid - (9753), roleid - (2), departmentid - (3) value,

Document document = await client.ReadDocumentAsync(UriFactory.CreateDocumentUri(DatabaseId, CollectionId, id)
                    , new RequestOptions { PartitionKey = new PartitionKey(new PartitionKey("9753/2/3"))) });

and got EXCEPTION

Unsupported ParitionKey value component '["/9753/2/3"]'. Numeric, string, bool, null, Undefined are the only supported types.

In addition, why would we need value for id and partition key at same time when retrieving an item from collection?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jharbieh picture jharbieh  Â·  3Comments

bdcoder2 picture bdcoder2  Â·  3Comments

varma31 picture varma31  Â·  3Comments

DeepPuddles picture DeepPuddles  Â·  3Comments

jamesgallagher-ie picture jamesgallagher-ie  Â·  3Comments