onesixtyfourth
onesixtyfourth

Reputation: 866

ReadDocumentAsync always fails claiming Id does not exist

I am querying Azure DocumentDb (cosmos) for a document that is present in the container:

try{
   doc = await client.ReadDocumentAsync(
   GetDocumentUri("tenantString-campaignId"),
       new RequestOptions 
       {
          PartitionKey = new PartitionKey(tenantString)
       });
   }
   catch(Exception e)
   {
       Console.WriteLine(e);
   } 

 for this document:

enter image description here

tenantString-campaignId is the id you can see here and tenantString alone is the partition key this is under. The tenant itself was passed in as a string and I had that working but now I have changed to passing a Tenant object and parsing the string required from it I am not returning the document.

I have tried a few different variations of tenantString and id and I can generate either a DocumentClientException, Id does not exist, Exception or it fails silently; no exception and returns to the calling method where it causes a NullReferenceException as no document is returned.

As far as I can make out from debugging through this I am constructing all my data correctly and yet no document is returned. Does anyone have any idea what I can try next?

Upvotes: 0

Views: 119

Answers (1)

Mark Brown
Mark Brown

Reputation: 8783

This syntax for the .NET SDK v2 is not correct. ReadDocumentAsync() should look like this.

var response = await client.ReadDocumentAsync(
    UriFactory.CreateDocumentUri(databaseName, collectionName, "SalesOrder1"), 
    new RequestOptions { PartitionKey = new PartitionKey("Account1") });

You can see more v2 samples here

Upvotes: 1

Related Questions