4

Using the Cosmos DB SQL API in the Cosmos SDK v3, I'm attempting to query the projects container, which has an /organization partition key.


var cosmosDb = await Storage.GetCosmosDb();
var queryDefinition = new QueryDefinition($"SELECT * FROM projects project WHERE project.organization = '{CurrentUser.Organization}'");
var queryRequestOptions = new QueryRequestOptions
{
    PartitionKey = new PartitionKey("organization"),
};
var projectsQuery = cosmosDb.Containers[typeof(Project)]
    .GetItemQueryIterator<Project>(queryDefinition, null, queryRequestOptions);
var projects = new List<Project>();
while (projectsQuery.HasMoreResults)
{
    projects.AddRange(await projectsQuery.ReadNextAsync());
}

The result of this is an error:

Response status code does not indicate success: 400 Substatus: 0 Reason: (Response status code does not indicate success: 400 Substatus: 0 Reason: (Gateway Failed to Retrieve Query Plan: Unknown QueryFeatures: NonValueAggregateActivityId: ceb5a509-36a0-4e20-87cd-32b6425dc757, Microsoft.Azure.Documents.Common/2.4.0.0, Windows/10.0.18362 cosmos-netstandard-sdk/3.2.1).).

Am I missing something obvious? What does this error mean?

Scotty H
  • 6,432
  • 6
  • 41
  • 94
  • Which SDK version are you using and are you running against a live account or the emulator? – Matias Quaranta Sep 26 '19 at 20:54
  • @MatiasQuaranta I'm using v3 and running against the emulator. – Scotty H Sep 26 '19 at 21:07
  • It seems like your Emulator might be old, can you try uninstalling and downloading the latest version? – Matias Quaranta Sep 26 '19 at 21:20
  • @MatiasQuaranta updated from 2.4.5 to 2.5.6 just now, and I still have that error. Restarted the computer. Any other ideas? – Scotty H Sep 26 '19 at 21:38
  • This problem seems to be isolated to querying. I am able to insert. – Scotty H Sep 26 '19 at 21:49
  • Try using Reset Data on the Emulator context menu. If that doesn't work, stop the emulator, delete the %LocalAppData%\CosmosDBEmulator folder, and start the emulator. – Matias Quaranta Sep 26 '19 at 22:58
  • @MatiasQuaranta Thanks, but same error I'm afraid. Would it help if I tried to make a repo with a minimum reproducible example, or are you pretty sure this is a local emulator problem? – Scotty H Sep 26 '19 at 23:05
  • If you run the code against a real account, it won't hit the error. Did you cleanup the LocalAppData folder too? – Matias Quaranta Sep 26 '19 at 23:14
  • I changed the endpoint and auth key to our develop Cosmos database, and that worked. I did delete the %LocalAppData%\CosmosDBEmulator. Maybe I need to try uninstalling and reinstalling the emulator. – Scotty H Sep 26 '19 at 23:20
  • This is failing on multiple machines, despite doing a clean install after deleting %LocalAppData%\CosmosDBEmulator. – Scotty H Sep 27 '19 at 13:43

3 Answers3

2

Updating the CosmosDB Emulator to the last version should fix the issue.

I had the issue with 2.4.5 and don't have it anymore with 2.5.7.

Benjamin Talmard
  • 1,773
  • 11
  • 21
1

This has been detected as an issue on SDK 3.2.0 when running in x86: https://github.com/Azure/azure-cosmos-dotnet-v3/issues/856

Current workaround is to run in x64 when working with the Emulator.

It should be fixed in the upcoming 3.2.1 release.

Matias Quaranta
  • 13,907
  • 1
  • 22
  • 47
0

For me, it was the scaling mode that was Manual in a collection, updated it to Autoscale, like the container setting and it worked.

Mehdi Benmoha
  • 3,694
  • 3
  • 23
  • 43