My functions just end with unexpected error every time and do not show anything in the Realm logs (I turned on logs in each of the function’s settings). I tried user authentication functions, system functions, runAsSystemUser=true, etc.
My setup is Atlas DB, Realm Web App, connect to Realm from Android Java SDK. I have users set up and log in with email and password from Java SDK before running a function. I initialize Realm and the MongodbApp. then call the function with functions.callFunctionAsync(name, parameters, callback). Function codes are very simple and don’t produce errors when I run them directly from Realm UI.
Example functions I tried:
exports = async function(arg){
let collection = context.services.get("mongodb-atlas").db(<Database>).collection(<Collection>);
let res = await collection.find({_id:BSON.ObjectId(<ID that exists>}).toArray();
res = "found: " + res;
if( context.user ){
res += "\nUsername is " + context.user.toString();
}
res += "\nRunning as system user: " + context.runningAsSystem() + ".";
return res;
};
and
exports = async function(arg){
let collection = context.services.get("mongodb-atlas").db(<DB>).collection(<Collection>);
let erg = await collection.updateOne({_id:BSON.ObjectId(<some id that exists>)}, {name:"New Name"});
res = "Changed #: " + erg.modifiedCount;
return res;
};