MongoDB setting permission for functions
Finally I got the answer. For executing user defined javascript functions in MongoDB first of all need to call db.loadServerScripts().

Every database in Mongo has a collection named system.js, which is in systems collections group.We can define our roles and permissions for collections and define privilage for system.js collection too.

If any function uses collections that we don't have permission to use, function will not execute and return authorization error, if collection have those privilages, funcion execute successfully