call

inline suspend fun <T> Functions.call(name: String, vararg args: Any?): T

Invokes an Atlas function.

Since the serialization engine does not support third-party libraries yet, there are some limitations in what types can be used as arguments and return types:

  • Primitives, Bson, MutableRealmInt, RealmUUID, ObjectId, RealmInstant, RealmAny, Array, Collection, and Map are valid argument types.

  • Results can only be deserialized to Bson, MutableRealmInt, RealmUUID, ObjectId, RealmInstant, RealmAny and primitive types

The Bson implementations for arrays or maps are BsonArray and BsonDocument, and they can be used as valid return types.

Return

result of the function call.

Parameters

name

name of the function to call.

args

arguments to the function.

T

the function return value type.

Throws

if the function failed in some way.

for other failures that can happen when communicating with App Services. See AppException for details.


inline suspend fun <T> Functions.call(name: String, callBuilderBlock: CallBuilder<T>.() -> Unit): T

Invokes an Atlas function using the EJson encoder defined in AppConfiguration.ejson.

Note This method supports full document serialization. The call arguments are defined with the builder CallBuilder. This same builder also allows to bind manually any argument or the return type to a specific serializer. Arguments and the return value will be encoded and decoded with AppConfiguration.ejson.

val dog: Dog = user.functions.call("RetrieveDog") {
add("a parameter")
add(1.5, FloatSerializer) // sets the serializer for this particular argument
returnValueSerializer = DogSerializer // sets the serializer for the return type
}

We cannot use a generic because:

Return

result of the function call.

Parameters

name

name of the function to call.

callBuilderBlock

code block that sets the call arguments and serializers.

T

the function return value type.