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/java/app-services/call-a-function/ below:

Call a Function - Java SDK - Atlas Device SDKs

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

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

To execute a function from the SDK, use the getFunctions() method of the your App to retrieve a Functions manager. Pass the name and parameters of the function you would like to call to callFunction() or callFunctionAsync():

String appID = YOUR_APP_ID; App app = new App(new AppConfiguration.Builder(appID).build());Credentials credentials = Credentials.anonymous();app.loginAsync(credentials, it -> {    if (it.isSuccess()) {        User user = app.currentUser();        assert user != null;        Functions functionsManager = app.getFunctions(user);        List<Integer> args = Arrays.asList(1, 2);        functionsManager.callFunctionAsync("sum", args, Integer.class, result -> {            if (result.isSuccess()) {                Log.v("EXAMPLE", "Sum value: " + result.get());            } else {                Log.e("EXAMPLE", "failed to call sum function with: " + result.getError());            }        });    } else {        Log.e("EXAMPLE", "Error logging into the Realm app. Make sure that anonymous authentication is enabled. Error: " + it.getError());    }});
val appID = YOUR_APP_ID val app: App = App(AppConfiguration.Builder(appID).build())val anonymousCredentials: Credentials = Credentials.anonymous()app.loginAsync(anonymousCredentials) {    if (it.isSuccess) {        val user: User? = app.currentUser()        val functionsManager: Functions = app.getFunctions(user)        val args: List<Int> = listOf(1, 2)        functionsManager.callFunctionAsync("sum", args, Integer::class.java) { result ->            if (result.isSuccess) {                Log.v("EXAMPLE", "Sum value: ${result.get()}")            } else {                Log.e("EXAMPLE", "failed to call sum function with: " + result.error)            }        }    } else {        Log.e("EXAMPLE", "Error logging into the Realm app. Make sure that anonymous authentication is enabled. Error: " + it.error)    }}

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