Mongodb server side functions vs aggregate operations

Hello guys. I have a very complex queries for working with arrays. I know that i can use raw server side functions in raw js and it will be simpler that using aggregation framework directives for working with arrays. But in doc i read that server side functions is not recommend to use, and it has bad performance.

Can you please say, should i do all stuff using complex directives or it will be better to use native js and pros and cos of this two approach.

My case looks like this: