I'm trying to fetch a list of items from a container ordered by a specific field.
Here's my CosmosDB Binding with SQL Query:
[FunctionName("FilterEvents")]
public static IActionResult FilterEvents(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "events/{PartitionKey}/{Order}/{SearchTerm}")] HttpRequest req,
[CosmosDB(
databaseName: Constants.DatabaseName,
collectionName: Constants.ContainerName,
ConnectionStringSetting = "CosmosDBConnectionString",
SqlQuery = "SELECT * " +
"FROM c " +
"WHERE c.email = {PartitionKey} AND CONTAINS(c.title, {SearchTerm})" +
"ORDER BY c.participantsCount {Order}"
)] IEnumerable<Event> events,
string PartitionKey,
string Order,
string SearchTerm,
ILogger log)
{
...
Console.WriteLine(PartitionKey);
Console.WriteLine(Order);
Console.WriteLine(SearchTerm);
}
When I invoke this API with this parameters:
https://../api/events/someone@gmail.com/ASC/event
I get the following error: :(
System.Private.CoreLib: Exception while executing function: FilterEvents.
Microsoft.Azure.WebJobs.Host: Exception binding parameter 'events'.
Microsoft.Azure.DocumentDB.Core: Message:
{
"errors":[
{
"severity":"Error",
"location": {
"start":101,
"end":107},
"code":"SC1001",
"message":"Syntax error, incorrect syntax near '@Order'."
}
]
}
[2022-07-07T13:49:53.666Z] ActivityId: 2a1a4919-f6e9-4b10-81b3-2ff2aa9d0159, Microsoft.Azure.Documents.Common/2.14.0, Windows/10.0.22621 documentdb-netcore-sdk/2.13.1.
=> When I simply remove that ORDER BY clause from my SQL Query,
i.e, SELECT * FROM c WHERE c.email = {PartitionKey} AND CONTAINS(c.title, {SearchTerm})
and invoke with the same URL Parameters, https://../api/events/someone@gmail.com/ASC/event
I could even see the values getting printed in the console:
Console.WriteLine(PartitionKey); // someone@gmail.com
Console.WriteLine(Order); // ASC
Console.WriteLine(SearchTerm); // event
=> Also, when I hardcode the value 'ASC' or 'DESC' in place of {Order}
, things just work as expected.
I couldn't find any information on why this is not working. Any suggestion would be much helpful here.
Thanks in advance.