Where i can use server side Javascript in MongoDB and what are the limitations?

Hello

Where we can use server side Javascript in MongoDB?
And what limitations we have in each use case

For example in $function aggregate operator,i can use only 1 function without dependencies
as far as i know,so all code should be inside the function body.

Thank you