azure-sdk-for-go icon indicating copy to clipboard operation
azure-sdk-for-go copied to clipboard

azcosmos: how to leave partition key unset?

Open harriblex opened this issue 2 years ago • 5 comments

The azcosmos container client calls all require a partition key:

itemResponse, err = container.ReplaceItem(context, pk, id, marshalledReplace, nil)

I have a container where the partition key values are undefined that I have to interact with, it is unclear how to construct an undefined partition key. Default object gives http 400.

Thanks

harriblex avatar Sep 21 '22 18:09 harriblex

Hi @harriblex. Thank you for your feedback and we will look into it soon. Meanwhile, feel free to share your experience using the Azure SDK in this survey.

ghost avatar Sep 21 '22 18:09 ghost

Hello, I believe I have the same issue.

For context the partition key path in the container is /_partitionKey, however the field is unset in all the document bodies inside the container (the key value pair does not exist). Unclear how to interact with these documents using the go sdk

HarryVolek avatar Sep 21 '22 20:09 HarryVolek

In the event this is impossible with the go sdk, could guidance be given on how to construct the http request?

Does the X-Ms-Documentdb-Partitionkey header need set in this case? If so, what does the value need to be?

HarryVolek avatar Sep 21 '22 21:09 HarryVolek

Ok, a default azcosmos.PartitionKey{} does work in this case. I was testing against a newly created cosmos with a partition key path set to _partitionKey to replicate the behavior of the old system, however this does not behave the same as a cosmos instance that was actually migrated: https://learn.microsoft.com/en-us/azure/cosmos-db/sql/migrate-containers-partitioned-to-nonpartitioned?tabs=dotnetv3 Caused some confusion

HarryVolek avatar Sep 21 '22 21:09 HarryVolek

I guess that we would need to support setting the None/Null partition key values as explicit types, like NewPartitionKeyNone and NewPartitionKeyNull.

ealsur avatar Sep 21 '22 22:09 ealsur

Any updates on this?

We have a similar problem when we try to use the azcosmos container client with NewQueryItemsPager as shown below. Our use case requires that the partition key can be left unset in the situations where we don't know the value of the ID used as partition key in Cosmos DB.

queryPager := container.NewQueryItemsPager(query, partitionKey, options)

The API in question currently supports requests where a user profile can be fetched based on different types of IDs, depending on which ID the consumer possesses. The ID that is used as partition key in Cosmos DB is not available for all consumers so we need to be able to handle the request and leave the key unset for some queries. When I try to set the partition key to an empty string "", "{}" or use the azcosmos.PartitionKey{} object the query returns no data or a 400 Bad Request.

In order to use this package, we need to be able to run the query without the partition key.

marilangaas avatar Nov 02 '22 12:11 marilangaas

@marilangaas I believe what you are asking is cross partition queries: https://github.com/Azure/azure-sdk-for-go/issues/18578

This issue is different. This issue is about interacting with documents that do not have a partition key value (they don't have the property). The same concept applied to queries would be a query on documents that have no partition key (which is still a single partition query).

ealsur avatar Nov 02 '22 13:11 ealsur