0

I have a CosmosDB database with one collection. If I go on Azure portal to the CosmosDB section, and then to the entity explorer, I can see the database name. If I put that database name in this code (client is a DocumentClient):

client.CreateDatabaseQuery().Where(d => d.Id == databaseName).AsEnumerable().FirstOrDefault();

It returns an exception:

System.AggregateException: 'One or more errors occurred. (The given header was not found.)'

Has anyone seen this before?

JakeJ
  • 2,361
  • 5
  • 23
  • 35
  • I was using the CloudTable object to get a reference to the collection by parsing the storage account, but this benchmark code goes about it a bit differently, and I've been trying to follow that so I can do performance tuning: Here's the performance tuning doc: https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/cosmos-db/performance-testing.md And here's the sample code: https://github.com/Azure/azure-documentdb-dotnet/blob/master/samples/documentdb-benchmark/Program.cs The relevant line is 303. – JakeJ Jun 01 '18 at 20:26
  • This also gets the same error: client.CreateDocumentCollectionQuery(UriFactory.CreateDatabaseUri(databaseName)).Where(c => c.Id == collectionName).AsEnumerable().FirstOrDefault(); – JakeJ Jun 01 '18 at 22:18
  • It almost seems like there's something wrong with the client as far as the endpoint it's expecting, but I got the endpoint from Azure portal from the CosmosDB section. It's of the format: https://.table.cosmosdb.azure.com:443/ – JakeJ Jun 01 '18 at 22:19
  • OK, I've started to get a different error now, I think I'm kind of out of the woods: I had to give the client a different format of endpoint at initialization and for the query. From this document: https://learn.microsoft.com/en-us/rest/api/cosmos-db/get-a-document See the request URI format there (I used it for the endpoint as well). I left out the doc-id from that and put a .Where(c => c.id == " – JakeJ Jun 01 '18 at 22:38
  • Talking about unfriendly errors for developers getting started with cosmosDB though - Microsoft really needs to fix that. The endpoint above doesn't match what you'll find in Azure at all. They either need to fix the DocumentClient SQL API to use the Azure portal given endpoint or give both endpoint types on Azure. – JakeJ Jun 01 '18 at 22:40
  • Check the InnerException. It has no visible reason in terms of query structure, why it wouldn't work. – Nick Chapsas Jun 01 '18 at 23:32
  • "The given header was not found" comes from the inner exception / is (or rather was - when I was still stuck on that error) the inner exception. The only matching results I could find for that were related to the HttpClient. That's why I thought maybe it was an invalid endpoint. – JakeJ Jun 03 '18 at 16:54
  • Did you use [Microsoft.Azure.Documents.Client.DocumentClient] to query for Cosmos Table API ? – Lee Liu Jun 05 '18 at 05:32
  • I think so Lee Liu. I was using the endpoint that it gives me at the Azure portal Cosmos DB section. I wonder if the endpoint there is different based on how you initialize the collection. – JakeJ Jun 07 '18 at 14:18

0 Answers0