Odd logging bug from Realm Function

I am seeing some strange behavior with the logging of a realm function.

When I run my function, it is supposed to query for documents in a collection and make updates to the documents it queries.

For a bit now, the logs I see are telling me that the function isn’t finding any documents, however, I know that it is actually updating these documents because I can see the updates happening in Atlas. Nothing else could be making these updates, only the function. And, in terms of the logging, I am referring to the logs inside of the function editor itself when you click the “Run” button.

Here’s a link to my function for context: App Services

One of the things it does is log the length of documents it found, and it currently keeps logging 0 even though it is obviously finding documents and making updates.

Also for further context, it was logging correctly beforehand.

Thanks!

Hey Lukas, looking at your function, it looks like you’re referring to this line:

const occasionsCursor = await Occasions.find({ nextOccasionDate: { $gt: yesterday, $lt: tomorrow } });

Are the print statements within each loop of your for loop working when it logs ‘0’? Another thing I can think of is that there was a bulk update to your application that caused updates and documents no longer match your query, or something about the timeliness of your query is no longer finding documents because it depends on when you run it.

Another way to double check is to use the data explorer to confirm that documents are being returned for your query is to use data explorer with the same query
https://cloud.mongodb.com/v2/5bc1648acf09a2891bf25a98#metrics/replicaSet/5e1b40339ccf64e656863ab3/explorer

Hi Sumedha!

Turns out I had a mistake going on. A return statement was placed incorrectly. :slight_smile: Once I fixed that, things were essentially running as normal.

I would however still say I have noticed some wonkiness with the way a Realm function logs things compared to what actually happens to my data. Is there a way to see a log of what happens to atlas data and what caused the CRUD operation?

I would however still say I have noticed some wonkiness with the way a Realm function logs things compared to what actually happens to my data.

Can you go a bit more into detail here? Are you referring to the console output from running a function or the actual logs for Realm.

Is there a way to see a log of what happens to atlas data and what caused the CRUD operation?

From Realm, you can actually download the logs and grep based on what you’re looking for (e.g. Function updates, graphQL, etc.

Sorry, the console output. Not the actual logs for Realm.

That looks like a nice trick. Thanks!

The issue is that the console output didn’t show I was making changes, I had console logs that would have ran if I did, but my data was updated. So I know that the console output didn’t match what had actually happened. Wish I could provide more insight on this because I know that’s very vague but that’s all I’ve got.