Reputation: 6700
I am attempting to run a very simple query against my Azure CosmosDb instance. Here is the query:
var query = container.GetItemQueryIterator<string>(new QueryDefinition("SELECT c.id FROM c"));
while (query.HasMoreResults)
{
var feed = query.ReadNextAsync().Result;
var ids = feed.Select(x => x);
foreach(var id in ids)
{
idsInDatabase.Add(id);
}
}
return idsInDatabase.ToArray();
But when it executes, I get an error stating that there is an "Unexpected character" in line 1, position 2, as seen below:
It's like it is trying to parse JSON instead of my SQL query. This example seems to follow the examples I've seen online. What am I missing here?
Upvotes: 0
Views: 376
Reputation: 15613
The result of that query is a JSON that contains an "id" property, not a string, you are not using VALUE.
Have you tried with a Type like:
public class MyResult
{
public string id { get; set; }
}
var query = container.GetItemQueryIterator<MyResult>(new QueryDefinition("SELECT c.id FROM c"));
while (query.HasMoreResults)
{
var feed = query.ReadNextAsync().Result;
foreach(MyResult result in feed)
{
idsInDatabase.Add(result.id);
}
}
return idsInDatabase.ToArray();
Upvotes: 1