Azure-docs: Code sample issue

Created on 2 Mar 2018  ·  10Comments  ·  Source: MicrosoftDocs/azure-docs

Hello,

If you create the collection manually and run the sample app, when you click on Edit, you get the following error:
"PartitionKey extracted from document doesn't match the one specified in the header"

The code in the sample app specifies a partition key that is listed in the docs as optional. I tried to resolve this by re-creating the collection manually, but I can't find how to create the partition key of /category like the sample app has (using "Add unique key" did not work neither).

The only way that I can find to use the sample app is to not have any collections in the database and then let the sample app create the collection with the /category partition key specification.


Document Details

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

  • ID: 4255f572-38cc-08aa-6fb7-08c919713cf9
  • Version Independent ID: c04fe4dd-e75d-1028-8f2e-154d8c303da2
  • Content
  • Content Source
  • Service: cosmos-db
assigned-to-author cosmos-dsvc doc-bug resolved triaged

Most helpful comment

@snehagunda @joseph4tw - I'm back. Feel free to assign this to me.

All 10 comments

Follow-up, I just noticed that if I specify the storage capacity to Unlimited then I get an option to specify the Partition key which could be set to /category, but you can't do that with the Fixed (10 GB) option, which the docs show to use. The problem is that the code sample assumes you set the Partition key which isn't the case.

So either the docs need to be updated or the sample app.

If updating the sample app, you could change DocumentDBRepository.cs line 26 from:

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

To:

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

@joseph4tw Thanks for pointing out the discrepancy and also for digging deep and actually sharing what you found!
I have assigned this issue to the content author to investigate and see if the document needs an update or the sample.

@mimig1 tagging you here as FYI. @SnehaGunda - Please take a look while Mimi is out.

@amanarneja happy to help! 👍

I was also willing to make a PR to update the sample code, but then I thought about it and figured I should let the doc authors decide what is best.

Thanks again @joseph4tw . @SnehaGunda - once you figure out the next steps, update this thread, also let Joseph know if he should just submit the PR.

@snehagunda @joseph4tw - I'm back. Feel free to assign this to me.

@joseph4tw sorry for the delay, please go ahead with submitting the PR and tag @mimig1 or me, we will review it.

@SnehaGunda / @mimig1 sounds good. I'll have an update soon.

Just as an FYI, if I update the code as I mentioned earlier, then the doc has to be updated slightly as well (there is a code snippet that is in the docs that needs to be updated, too). I'll make an update to both parts and try to link them properly since the docs and the sample are in different repos.

@SnehaGunda / @mimig1 here are the relevant PRs:
https://github.com/MicrosoftDocs/azure-docs/pull/5319
https://github.com/Azure-Samples/documentdb-dotnet-todo-app/pull/9

Please let me know if you have any questions or concerns.

We reviewed your change, the PR will be merged soon. @joseph4tw we will close this issue, if you have any further questions feel free to reopen or create a new one.

please-close

Was this page helpful?
0 / 5 - 0 ratings