App Services Functions allow you to define and execute server-side logic for your application. You can call functions from your client applications as well as from other functions, and in JSON expressions throughout Realm. For more information, see App Services Functions.
If you experience issues executing a function, troubleshoot using the following steps:
1. Check the function on the Functions page in your Realm App:
Confirm the function settings are appropriate. For example, check the authentication method.
Confirm your code is syntactically and functionally correct in the Function Editor.
If you make any changes to your App Services App, remember to click Review & Deploy in the blue banner at the top of the App Services UI to deploy the changes. See Deploy from the App Services UI and Why are the user modifications made to the App Services UI not reflected in the App Services Application?
2. Check the App Services Logs for entries related to the function:
You can enable Log Function Arguments in the function settings so that the arguments that a function receives are included in the log entry for each execution of the function.
You can log the parameters being passed to the function by adding
console.log(<some parameters>)
to your function code.
3. Test the function in the Console tab under the Function Editor:
โ
As the System User, click Console at the bottom and fill in the parameters for calling the function. Click Run.
If you receive an error message, review the corresponding function code and address the issue based on the error you receive.
If the function executes successfully, run the function again with a different user. Realm uses the System user by default when a user is not selected. This user has advanced privileges and automatically bypasses all rules. See Troubleshooting: Operations not permitted.
Click Change User next to the Run button and select the Realm user you want to use, then click Run.
If you encounter an error in this step, confirm you have granted the appropriate permission to the selected Realm user on the Rules page. If you are using Realm user metadata, ensure that the Realm user has all the necessary metadata.
For further help, contact MongoDB Support with the following information:
the name of the function with issues and the arguments you have passed in when executing the function
the full output of any informational or error messages logged upon encountering the issue
the date, time, and timezone of the first and the most recent occurrence of this issue