I have created an Azure Function that gets triggered with an HTTP POST request.
The request has a body like the following:
{
"start": '2018-07-25T08:47:16.094Z',
"end": '2018-07-25T08:47:24.686Z'
}
index.js
module.exports = async function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
var inputDocument = context.bindings.inputDocument;
context.log("INPUT DOCUMENT: " + JSON.stringify(inputDocument));
context.res = {
status: 200,
body: "OK",
};
};
function.json
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "cosmosDB",
"name": "inputDocument",
"databaseName": "Messages",
"collectionName": "Collection1",
"sqlQuery": "SELECT * FROM Collection1 c WHERE c.message.timestamp>={start} AND c.message.timestamp<={end}",
"connectionStringSetting": "cosmosdbaccount_DOCUMENTDB",
"direction": "in"
}
]
}
I would like to query a CosmosDB instance with these two parameters like this:
"sqlQuery": "SELECT * FROM Collection1 c WHERE c.message.timestamp>={start} AND c.message.timestamp<={end}",
Doing it like I show here results in the CosmosDB's inputBinding beeing undefined.
2018-12-13T08:19:54.332 [Information] Executing 'Functions.Function1' (Reason='This function was programmatically called via the host APIs.', Id=af8090a4-5fab-4fbd-b26f-a045d8900d9b)
2018-12-13T08:19:56.704 [Information] JavaScript HTTP trigger function processed a request.
2018-12-13T08:19:56.711 [Information] INPUT DOCUMENT: []
2018-12-13T08:19:56.755 [Information] Executed 'Functions.Function1' (Succeeded, Id=af8090a4-5fab-4fbd-b26f-a045d8900d9b)
If I run the same exact query replacing start
and end
with the correct ISO timestamps in the CosmosDB Data Explorer it returns all four documents.
Am I missing something? I really didn't find anything about this topic online so I hope someone has already stumbled upon it.
Thanks a lot in advance!