Docs Menu

Call a Function

On this page

  • Overview
  • Usage
  • Call a Function
  • Call a Function Programmatically

You can call a function from a connected client application.

The examples in this section demonstrate calling a simple function named sum that takes two arguments, adds them, and returns the result:

// sum: adds two numbers
exports = function (a, b) {
return a + b;
};

In the Node SDK you call functions as a logged in user with the User.functions interface. There are two ways to call a function:

  • You can call a function as if was a method defined locally on the User.functions interface.
  • You can call the User.functions.callFunction() method to call a function by providing its stringified name and a list of arguments.
const result = await user.functions.sum(2, 3);
const functionName = "sum";
const args = [2, 3];
const result = await user.callFunction(functionName, ...args);
←  Access Custom User DataLink User Identities →
Give Feedback
© 2022 MongoDB, Inc.

About

  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.