Following this [doc][1]
[1]: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-cosmosdb-v2-input?tabs=javascript with aim of Queue trigger, get multiple docs, using SqlQuery.
My function (index) is as follows:
module.exports = function (context, req) {
var performances = context.bindings.performances;
context.log("The list is this long : " + performances.length);
context.log("The requested course code is : " + (req.query.CourseID || (req.body && req.body.CourseID)));
if (performances.length !== 0) {
context.res = {
body: JSON.stringify(performances),
headers: {
'Content-Type': 'application/json'
}
};
}
else {
context.res = {
status: 404,
body: "No Performance found",
headers: {
'Content-Type': 'application/json'
}
};
}
context.done();
};
and my function.json is as follows:
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "cosmosDB",
"direction": "in",
"name": "performances",
"databaseName": "Core",
"collectionName": "StudentPerformance",
"connectionStringSetting": "CosmoConnectionString",
"partitionKey": "/UserID",
"sqlQuery": "SELECT * from c where c.CourseID = {CourseID}"
}
]
}
- I attempted to query Cosmos DB from the Microsoft Azure Storage Explorer and got a 200. Which implies my query was OK.
- I then attempted to use Azure Function with Cosmos input Binding. I got the results I wanted.
- Attempting to make the query dynamic has proved to be a challenge. Any Ideas?
I keep getting an empty list. 😭
CourseID is passed to the query I think so without explicitly specifying it?