question

kanishka-3236 avatar image
0 Votes"
kanishka-3236 asked AnuragSharma-MSFT commented

How to Get document using cosmos SQL Rest API when partition key for document is empty ?

I am using postman collection for the Cosmos DB SQL Rest Api to fetch a document . My collection has a partition key defined but the document I am trying to fetch has no value for that key . What should I specify in the x-ms-documentdb-partitionkey header .
I have tried with values "null" and "Undefined.Value" but that didn't work .

azure-cosmos-db
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @kanishka-3236, just wanted to check if you need any other details. If answer helped your query, you can mark it 'Accept Answer'.

0 Votes 0 ·

1 Answer

AnuragSharma-MSFT avatar image
0 Votes"
AnuragSharma-MSFT answered

Hi @kanishka-3236, welcome to Microsoft Q&A forum.

Currently for getting the document through rest api, x-ms-documentdb-partitionkey is a mandatory header to pass(if we created the collections with partition key) with one of the partition key value. If we go through the article, it mentions "The Get Document operation retrieves a document by its partition key and document key.". There is a limitation of passing or retrieving the documents with no/null partition key.

However we can still get the list of all the documents in the collections which would not need us to pass any partition key like below:

 https://{
                 {DocumentDBHost}}/dbs/newdb/colls/container/docs

Also the efficient design of cosmos container would need us to provide a partition key to each and every document. We can still create docs without it but that would be not ideal situation.

Please let us know if this helps or we can discuss further.


If answer resolves your query you can mark it 'Accept Answer'







5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.