exports = async function(email, movie, db_bool){
// Accessing a mongodb service:
let mongodb = null
let db_target = null
// true: favs / false: later
if( db_bool ) db_target = context.services.get("mongodb-atlas").db("lovies").collection("favorites");
else db_target = context.services.get("mongodb-atlas").db("lovies").collection("later");
let insertion = await db_target.findOne({email:email})
let action_option = null
if( insertion ) action_option = await db_target.updateOne({email: email}, {$addToSet: {"movie_id":movie}})
else action_option = await db_target.insertOne({email: email, movie_id:[movie]})
return action_option;
};
I have this function in Realm site.
The Idea
To have a function to be called with three parameters to save a movie id in a collection relaying in a boolean if/else.
It works in Test
This function works fine in the editor.
Not work from site
It’s not working from site, a Reactjs Front-End that works with realm web.
Cases
I read this post: Setting up Custom User Data and this post: Link a MongoDB Data Source and I have setted an atlas-collection
and atlas-later
rules.
The problem
This function was planed to save data in one or the other collection but throw Error: Request failed (POST https://stitch.mongodb.com/api/client/v2.0/....../functions/call): no rule exists for namespace 'lovies.later'
and the same for lovies.favorites
I need a way to save movies id from Reactjs with Realm to be retrieved later in a page.