I am trying to trigger azure function using Service Bus Queue trigger, which works fine. What I also want to do is use Cosmos Db input binding on the same function. The function gets triggered with the specific document and gets result with the input binding for simple query like:
Select * from c
But with a WHERE clause the same query does not return anything, though the condition is right and data is there in the DB against the contract Id passed in from the trigger:
Select * from c WHERE c.contractId = {contractId}
Following is the code of the Azure Function
#r "Microsoft.Azure.DocumentDB.Core"
using System;
using System.Collections.Generic;
using Microsoft.Azure.Documents;
public static void Run(IReadOnlyList<Document> input, ILogger log, IEnumerable<dynamic> documents)
{
if (input != null && input.Count > 0)
{
log.LogInformation("Documents modified " + input.Count);
log.LogInformation("First document Id " + input[0]);
}
}
function.json
{
"bindings": [
{
"name": "myQueueItem",
"type": "serviceBusTrigger",
"direction": "in",
"queueName": "tripend",
"connection": "mobiiot_RootManageSharedAccessKey_SERVICEBUS"
},
{
"type": "cosmosDB",
"name": "documents",
"databaseName": "ToDoList",
"collectionName": "Items",
"connectionStringSetting": "mobiiot_DOCUMENTDB",
"direction": "in",
"sqlQuery": "SELECT * from c where c.contractId= {contractId}"
}
]
}
Trigger Data coming into Azure Function:
{"vin":"WP0ZZZ99ZJS167001","milage":780.3333,"contractId":"19277",
"lat":51.47404,"lon":-0.45299000000000006,"noOfHardBreaks":0,"fuelConsumptionRate":22,
"speed":96,"status":"droppedOff","EventProcessedUtcTime":"2018-12-10T09:14:51.6474889Z",
"PartitionId":0,"EventEnqueuedUtcTime":"2018-12-10T09:14:51.5350000Z",
"IoTHub":{"MessageId":null,"CorrelationId":null,"ConnectionDeviceId":"WP0ZZZ99ZJS167001",
"ConnectionDeviceGenerationId":"636795108399273130",
"EnqueuedTime":"2018-12-10T09:14:51.5470000Z","StreamId":null}}
function.json
and what's the data type ofcontractId
, String or others e.g Number? – Jerry Liu