Docs Menu

Function Configuration Files

On this page

  • Function Manifest
  • Function Source Code
app/
└── functions/
├── config.json
└── <function>.js

Every function in your app has a corresponding metadata entry in the function manifest file: /functions/config.json.

Tip

Realm automatically adds functions to the manifest on import if they don't already have a configuration defined. If you're okay with the default settings, you can skip defining the configuration for a function and let Realm do it for you. The manifest will include the generated configurations the next time you export or pull your app.

functions/config.json
[
{
"name": "<Function Name>",
"private": <Boolean>,
"can_evaluate": { <JSON Expression> },
"disable_arg_logs": <Boolean>,
"run_as_system": <Boolean>,
"run_as_user_id": "<Realm User ID>",
"run_as_user_id_script_source": "<Function Source Code>"
},
...
]
Field
Description
name
String
The name of the function. The name must match the file name of a source code file and be unique among all functions in your application.
private
Boolean
If true, this function may only be called from other functions or in %function rule expressions. You cannot call a private function directly from a client application or with an SDK.
can_evaluate
JSON Expression (default: true)
A JSON expression that evaluates to true if the function is allowed to execute. Realm evaluates this expression for every incoming request.
disable_arg_logs
Boolean
If true, Realm omits the arguments provided to the function from the function execution log entry.
run_as_system
Boolean
If true, this function runs as the system user. This overrides any values defined for run_as_user_id and run_as_user_id_script_source.
run_as_user_id
String
The unique ID of a Realm User that the function always executes as. Cannot be used with run_as_user_id_script_source.
run_as_user_id_script_source
String
A stringified function that runs whenever the function is called and returns the unique ID of a Realm User that the function executes as. Cannot be used with run_as_user_id.

You define a function's source code in a .js file within the /functions directory that uses the function name as its file name. Each file must export the main function that runs whenever a request calls the function.

Important

All of your function source code files must be in the /functions directory. Realm does not recognize functions nested in subdirectories of /functions.

/functions/<function name>.js
exports = function addOne(input) {
if(typeof input !== "number") {
throw new Error("You must call addOne() with a number");
}
return input + 1;
};
Give Feedback
© 2021 MongoDB, Inc.

About

  • Careers
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2021 MongoDB, Inc.