I am trying to write a query in Data Explorer over a Cosmos DB to give me a list of results where the order has a discount applied. That requires that I examine every element of the Totals array for a Discounts element that is not empty.
I've tried to use ARRAY_LENGTH within ARRAY_CONTAINS as shown below and that didn't return a result set. I know the ARRAY_CONTAINS is use to look for a field value within an array, but I was hoping that it would accept ARRAY_LENGTH command.
SELECT * FROM c where ARRAY_CONTAINS(c.OrderHeader.Totals,{ARRAY_LENGTH(Discounts):1},true))
I've also tried to check for a value in CampaignId field of the Discounts array using the following query. It didn't return a result set.
SELECT * FROM c where ARRAY_CONTAINS(c.OrderHeader.Totals.Discounts,{CampaignId:null},false)
I would assume there's a way to do this, so any input would be greatly appreciated!
{
"OrderHeader": {
"Totals": [
{
"Currency": "CAD",
"Price": 10.00,
"Discounts": []
},
{
"Currency": "CAD",
"Price": 20.00,
"Discounts": []
},
{
"Currency": "CAD",
"Price": 30.00,
"Discounts": [
{
"CampaignId": "Campaign2",
"CouponDefinition": null,
}
]
}
}