Can a Realm Instance be created in a Realm Function?

Hi,

I am trying to explore if it is possible for a Realm Function to include app = New Realm.App(“appid”) ?

Can I manually upload an external dependency based on the realm npm package or is it already accessible.

I’m looking to hide the app id from the client side, and one way I can think of (if possible) is to have the client side fetch a webhook on Realm which then triggers a long function including a Realm Instance.

1 Like

Hi,

Creating a Realm instance in the function is not possible but you could use the Realm Admin API to retrieve the application definition for the app in question to send to the client. The response will contain the client_app_id you need for New Realm.App().

The function can use context.http.get() to make the request to the API.

Example of function:

exports = async function() {
  
  const response = await context.http.get({ 
    url: "https://realm.mongodb.com/api/admin/v3.0/groups/<project_id>/apps/<realm_app_hexid>",
    headers:{
  "Content-Type": [ "application/json" ],
  "Authorization": [ "Bearer <admin_api_token>" ]
}
  });
      return EJSON.parse(response.body.text());
};

Regards

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.