08-07-2023 06:39 AM - edited 08-07-2023 06:49 AM
I have a JSON payload with a nested array (below). I am trying to use the filter Snap to select specific items only. Unfortunately, the expressions that I have tried have not worked - they select everything or nothing.
$myList.filter(x => x.num==1)
$myList.filter(x => x.num==1)[0].num==1
[{"myList":[{"msg":"Hello, World1","num":1,"type":"Q"},{"msg":"Hello, World2","num":2,"type":"X"},{"msg":"Hello, World3","num":3,"type":"Q"}]}]
Any help or suggestions will be very much appreciated.
Solved! Go to Solution.
08-07-2023 07:31 AM
08-07-2023 07:31 AM
08-07-2023 07:32 AM
@LanreOyewole - I think what you really want to do is put your expression in a Mapper and target back to the same field name:
08-07-2023 08:06 AM
Hello @koryknick,
Thanks a lot for the response, much appreciated.
I have already used the mapper, and that works fine. However, I am going through the training materials and I noticed that the filter Snap is used for de-duplication in one of the examples. The documentation also says "This Snap filters a document stream based on a expression", which made me try to use it to select specific documents.
08-07-2023 08:44 AM
So the Filter works at the document level - what you had was a single document with an array, which is why I went for the Mapper. If this is confusing, you can share your pipeline which might let me explain it more clearly with an example.