# Solution to filter nested multiple content links

**URL:** <https://discourse.getcockpit.com/t/solution-to-filter-nested-multiple-content-links/3167>\
**Category:** Cockpit v2\
**Created:** [March 17, 2025, 6:20pm UTC](https://discourse.getcockpit.com/t/solution-to-filter-nested-multiple-content-links/3167 "2025-03-17T18:20:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![goosen999](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/goosen999/32/1412_2.png) [@goosen999](https://discourse.getcockpit.com/u/goosen999)\
**Post date:** [March 17, 2025, 6:20pm UTC](https://discourse.getcockpit.com/t/solution-to-filter-nested-multiple-content-links/3167/1 "2025-03-17T18:20:04Z")

</div>

I know this subject has already been talked and some solutions have been provided but I would like to purpose one that can be integrated to the core.  
It’s a one line solution and for the specific purpose of multiple content links!

I’ve ben using it without issues with MongoLite but I believe it works with others.  
I cant apply it as an addon because it belongs on the core and addon solutions (post DB retrieval) seems hacky.

```auto
if (count($a) && array_key_exists('_model', $a[0])) $a = array_column($a, '_id');

```

This line must be added to the ‘$has’ switch option on the /lib/MongoLite/UtilArrayQuery.php

Final result like this:

```auto
case '$has' :
    if (\is_array($b))
        throw new \InvalidArgumentException('Invalid argument for $has array not supported');
    if (!\is_array($a)) $a = @\json_decode($a, true) ? : [];
    if (count($a) && array_key_exists('_model', $a[0]))
        $a = array_column($a, '_id');
    $r = \in_array($b, $a);
    break;

```

To use it, using blog examples, apply a _filter_ on _posts_ collection with {“categories”:{“$has”:“\<category\_id\>”}}", considering _categories_ is a Collection Link with multiple option active.

I hope @artur can check it out, review it and maybe make it available for everyone.

It’s been an issue on MongoLite usage and it can be a closed chapter!

Kind regards,  
Miguel Pereira
