Query to filter by filed in array of deeply nested documents

Hi, @jowitty, you can use a model like this:

{
  categories: [<Node>]
}

Node:
{
  "fieldToFilterBy": <String>
  "child": <Node>
}

You’ll set child’s value to null if it’s a leaf.
Then you’ll be able to solve your task by performing $graphLookup.

Edit: On second thought I realize that your data structure is more an array of arrays than a tree. So maybe the simple solution is like you suggested:

{
  "categories": [],
  "fieldsToFilterBy": [
    {
      "listPath": [{fieldsToFilterBy :"1"}, {fieldsToFilterBy :"2"}, {fieldsToFilterBy :"3"}]
    },
    {
      "listPath": [{fieldsToFilterBy :"5"}]
    }
  ]
}

Both options have cons and pros.
Good luck,
Rafael,