Reputation: 25
I need to query from CosmosDB for items that has a null array of data like a [null].
I tried query like this query SELECT TOP 1 c.id from c where ARRAY_CONTAINS(c.data1, [[null]], true). My intent is to query something like this.
SELECT TOP 1 c.id from c where ARRAY_CONTAINS(c.data1, [[null]], true)
NO result is returned for the above query.
var sampledata = `{
"id": 48259,
"data": [
[
{
"Elements": [
{
"QS": "",
"TypeC": "C",
"Id": 378,
"R": false,
"KTime": "0",
"AllKVal": "",
"KVal": "2",
"IsGreen": false
}
]
}
],
[
null,
{
"Elements": [
{
"QS": "",
"TypeC": "CM",
"Id": 243,
"R": "",
"KTime": "0",
"AllKVal": "",
"V": true,
"KVal": "2",
"IsGreen": false
}
]
}
]
],
"_ts": 1560943024
}`;
Upvotes: 1
Views: 4276
Reputation: 23782
I think i get your intention. Let us say, your data maybe like this:
{
"id": "48259",
"data": [
[
{
"Elements": [
{
"QS": "",
"TypeC": "C",
"Id": 378,
"R": false,
"KTime": "0",
"AllKVal": "",
"KVal": "2",
"IsGreen": false
}
]
}
],
[
null
],
[
null,
{
"Elements": [
{
"QS": "",
"TypeC": "CM",
"Id": 243,
"R": "",
"KTime": "0",
"AllKVal": "",
"V": true,
"KVal": "2",
"IsGreen": false
}
]
}
]
]
}
data array has element is entire null array:
or has element contains null value and other values.
If so,you could use join in your sql to deal with both of them.
SELECT distinct c.id from c
join data in c.data
where ARRAY_CONTAINS(c.data,[null],true)
or ARRAY_CONTAINS(data,[null],true)
Output:
Upvotes: 3