Realm Trigger executions not being logged

I have a simple trigger set up “onConfigChange” that runs when a document in my config collection is updated.

The function:

Screen Shot 2021-09-08 at 2.17.51 PM

The trigger says it was executed:

But it is not showing in the logs

I need to get the execution showing up in the logs so that I can see the console.log outputs while I write the function. This seemed to be working a couple hours ago but now any new trigger executions just don’t show up in the logs. Any ideas? Thanks

Hello @Shea_Dawson

My name is Josman and I am happy to assist you with this issue. We have a UI bug on the Latest Execution time in the trigger section. Currently, this label shows the latest update of this trigger’s settings instead of the current latest execution.

We have identified this and we are working on fixing it, but currently, I don’t have an ETA of when this is going to be fixed.

In this sense, and for your issue, do not use this as a reference for an execution of this trigger. Please, be aware that for an update to be executed the result of the update must be the following:

{ acknowledged: true,
  insertedId: null,
  matchedCount: 1,
  modifiedCount: 1,
  upsertedCount: 0 }

If matchedCount and modifiedCount is 0, this will not run the trigger. Could you please double-check that indeed the document is being updated without the trigger being fired?

Kind Regards,
Josman

1 Like

Hi Josman thanks for your response. I’ve had another go at this and this is what is happening.

UI bug on the Latest Execution time: For me, the value being displayed is actually the current time, not the latest update of the trigger’s settings. Every time I refresh there is a new value being displayed.

The writes are definitely successful - I am testing using Realm Studio to update documents in the collection. I did manage to get some trigger logs displaying this morning with the following function.

exports = function(changeEvent) {
  const bID = changeEvent.documentKey._id;
  console.log("BID IS", bID);
};

This logged the value as expected in the realm admin ui logs section. Great!

I then proceeded to continue writing my trigger function. But after testing the below, new trigger logs are no longer displaying again :frowning:

exports = function(changeEvent) {
  const bID = changeEvent.documentKey._id;
  console.log("BID IS", bID);
  try {
     const res = context.functions.execute("bEarthaUpdateLastModified", bID);  
     console.log("res", res)
   } catch(e) {
     console.log("error", e)
   }
};

Hello @Shea_Dawson

If you are planning use the returned value from the context.function.execute("bEarthaUpdateLastModified", bID); synchronously, you need to mark your function as async and add the await keyword.

exports = async function(changeEvent) {
  const bID = changeEvent.documentKey._id;
  console.log("BID IS", bID);
  try {
     const res = await context.functions.execute("bEarthaUpdateLastModified", bID);  
     console.log("res", res)
   } catch(e) {
     console.log("error", e)
   }
};

However, your function might still be executed even though you have not added the async feature.

In order to take a further look at what could be causing your issue, could you please share with me your Realm App URL?

Thank you

Please let me know if you have any additional questions or concerns regarding the details above.

Kind Regards,
Josman

1 Like