Forum Discussion
j_angelevski
2 years agoContributor III
Hi userg ,
Can you share how the input document looks like?
Not sure if both inputs are accessible within a single object. Assuming they are, you can use the following expression to compare the values in the arrays:
$Input2.map(val => { "values": val, "insert": val.map(v => $Input1.indexOf(v) != -1).filter(val => val == false).length == 0 ? true : false })
Sample input data:
[
{
"Input1": ["a", "b", "c", "d", "e", { "test": 1 }],
"Input2": [
["c", "a", "e"],
["a", "z"],
["a", "", "b"],
["a", { "test": 2 }]
]
}
]
Output:
[
{
"Input1":[ "a", "b", "c", "d", "e", { "test":1 } ],
"Input2":[
{
"values":[ "c", "a", "e" ],
"insert":true
},
{
"values":[ "a", "z" ],
"insert":false
},
{
"values":[ "a", "", "b" ],
"insert":false
},
{
"values":[ "a", { "test":2 } ],
"insert":false
}
]
}
]
This expression adds an additional flag ( "insert" ), to the Input2 and if all the values in the array exist in the Input1, then insert will be true otherwise false. You can then split the Input2 array to get the object as individual input documents and pass through only the values where insert flag is equal to true. That can be done with a Filter snap.