Realm Function with Webhook: No rule exists for namespace

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.

Hi @Puzzle_Dots and welcome in the MongoDB Community :muscle: !

Please check the function settings in Realm.

And check that you are using what you need.

Also go to Rules and make sure that you have a rule for all the collections you are using for the role that the authenticated user (if any) has.

The rules are here to ensure that the client isn’t touching (read/write) another collection (or fields) that it’s not supposed to. No rule == no access. It’s basically what the message you receive is telling you.

Cheers,
Maxime.