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

Call an Atlas Function - Kotlin SDK - Atlas Device SDKs

You can call an Atlas Function from a client application using the Realm Kotlin SDK. Functions are serverless JavaScript functions that let you define and execute server-side logic. These server-side Functions can run in the context of the authenticated user, and thus honor the rules, roles, and permissions that you have assigned to your data in Atlas.

New in version 1.9.0.

You can serialize Function arguments and return values using an EJSON encoder. For more information, including examples, refer to EJSON Encoding for Atlas.

For more information on configuring and writing Atlas Functions, refer to Atlas Functions in the App Services documentation.

  1. In an App Services App, define an Atlas Function.

  2. In your client project, initialize the App client.

  3. Then, authenticate a user. Functions are accessed through the User object.

Important

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

To call an Atlas Function from the Kotlin SDK, pass its name and all arguments to Functions.call().

Consider an Atlas Function running in an App Services App named sum that takes two arguments, adds them, and returns the result:

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

To call this Atlas Function from the Kotlin SDK:

runBlocking {    val app: App = App.create(appID)    val user = app.login(credentials)            val response = user.functions.call<Int>("sum", 1, 2)    print(response) }

Changed in version 1.9.0.

If you are using Kotlin SDK v1.9.0 or later, these limitations no longer apply.

Because the Kotlin serialization engine does not yet support third-party libraries, there are limitations to the types you can pass as arguments and the types you can deserialize the results to in a called Function.

You cannot pass objects as arguments.

The following are valid argument value types:

The following are valid return value types:


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