How are you executing the above function? As far as I am aware the only way it can be executed is by it being retrieved by the client (Shell, Node.JS app etc) and then sent executed outside the database sending the aggregtion back to the server like any other bit of code. Logically it also cannot be called by any other programming language other than JS as it’s not running on the database server but in the app code. system.js is not really any different to any other collection and MongoBD is just being used to store ‘data’ for your app - the data just happens to be pipeline defintions. No part of this is server side functions , stored procedures or server side javascript.
I could be wrong however but my understanding is all that was disabled years ago.