A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.mongodb.com/docs/atlas/device-sdks/sdk/node/app-services/call-a-function/ below:

Call a Function - Node.js SDK - Atlas Device SDKs

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

exports = function(a, b) {  return a + b;};
Important

Make sure to sanitize client data to protect against code injection when using Functions.

To call a function, you can either pass its name and arguments to User.callFunction() or call the function as if it was a method on the User.functions property.

Note Link a MongoDB Atlas Data Source

This example requires an App Services App with a linked Atlas data source. Replace <appId> in the code with your App ID, which you can find in the left navigation menu of the App Services UI.

const numA = 2;const numB = 3;const result = await user.functions.sum(numA, numB);const resultOfCallFunction = await user.callFunction("sum", numA, numB); console.log(  `Using the "functions.sum()" method: the sum of ${numA} + ${numB} = ${result}`);console.log(  `Using the "callFunction()" method: the sum of ${numA} + ${numB} = ${resultOfCallFunction}`);

When you run the code sample, your output should resemble the following:

Using the "functions.sum()" method: the sum of 2 + 3 = 5Using the "callFunction()" method: the sum of 2 + 3 = 5

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4