I had to follow solution n.2 from here
You must create a folder \cockpit-master\config (if it doesn’t exist) and add a file bootstrap.php in which you will add implementation to handle the event of collections.find.after.collectionName and you will be able to do extra database calls and add content to the response before it is returned to the client. (see example).