I just started playing around with functions and I am trying to write a simple HTTP trigger that does fetches all records within in a CosmosDb Collection's Partition. This sample test collection is a history kind of thing and the entries for a given resourcetype-resourceId look like this:
[{
"PartitionKey": "ResourceType|1234",
"id": "2b8a5545-a6ed-4057-886a-a9b082749001",
"Description": "Endity was created",
"TimeStamp": "2019-05-08T10:10:53.1402102+00:00",
},
{
"PartitionKey": "ResourceType|1234",
"id": "2b8a5545-a6ed-4057-886a-a9b082749001",
"Description": "Endity was modified",
"TimeStamp": "2019-05-08T11:10:53.1402102+00:00",
}]
The function looks something like this
[FunctionName("GetHistoryEntries")]
public static async Task<IEnumerable<HistoryEntry>> Run(
[HttpTrigger(AuthorizationLevel.Admin, "get", "post", Route = "resources/{id}/history")] HttpRequest req,
[CosmosDB(
databaseName: "theDb",
collectionName: "History",
ConnectionStringSetting = "theconnectionstring",
SqlQuery = "SELECT * from c where c.PartitionKey = 'ResourceType|{id}'")]
IEnumerable<HistoryEntry> entries,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
return entries;
}
That is always returning empty though, even though it works if I use the actual Document query and write the code to fetch read and convert and return. Having to write all that kind of misses the point of the simplicity for the use cases I was considering.
If I replace the {id} in the query for the actual value I get the right elements back, so it seems like the query is not being built correctly from the string template. Is that not supported? Will it be supported? Is there a way to get it working?
I just started playing around with functions and I am trying to write a simple HTTP trigger that does fetches all records within in a CosmosDb Collection's Partition. This sample test collection is a history kind of thing and the entries for a given resourcetype-resourceId look like this:
The function looks something like this
That is always returning empty though, even though it works if I use the actual Document query and write the code to fetch read and convert and return. Having to write all that kind of misses the point of the simplicity for the use cases I was considering.
If I replace the {id} in the query for the actual value I get the right elements back, so it seems like the query is not being built correctly from the string template. Is that not supported? Will it be supported? Is there a way to get it working?