MongoDB Realm - embedded array of objects not accessible in Mongo-Function via „FullDocument“

Hi @Dominik_Jell, I didn’t see “embedded” being set in the code you shared.

To troubleshoot this, we really need sample code that’s following the instructions but isn’t working as expected. If we can reproduce a problem then it’s much easier to figure out what’s happening.

1 Like

Hello!

I am encountering the same issue and can’t seem to figure out why my List of embedded objects isn’t accessible inside a Realm Function.

Was there an appropriate fix here?

HH

1 Like

Hi @Harry_Heffernan - welcome to the forum!

Would you be able to share example Object definitions and function code? If so, I can take a look at what’s not working.

Hello!

Thank you for your quick response, and all your many articles on using Realm. I would be nowhere without those resources. Here are the relevant object models:

I’m running a function on an Event insert and getting undefined when I look for “invitees” in the fullDocument object. I am sure that this field is being properly added to the inserted object because when I query the Events collection (just a simple eventsCollection.find()) from that same function, the document that is returned DOES include “invitees”

Thanks again

Harry

1 Like

Hi Harry, sorry for the delay – I needed to make some time to try reproducing the issue.

I created a mini repo that does reproduce it… GitHub - am-MongoDB/ListTest

My test confirmed that the embedded list was not available in the trigger when run for an insert, but it was there when the trigger ran for an update.

I’ll follow up with engineering.

2 Likes

Note that if you set the trigger to fire on replace (in addition to insert) then it fires a second time when you add the Event object – invitees is there when the trigger fires the second time with the replace operation. So, it looks like the syncing of the new Object results in 2 database writes:

  1. Insert the document without the embedded array
  2. Replace the document – this time including the embedded array

Maybe you can exploit this as a workaround?

1 Like

Confirmed with engineering that this is the expected behavior :frowning:

But, there’s a plan to fix it.

I’m watching the issue and will report back when I see that it’s been fixed. In the meantime, triggering on the replace might be the best option.

2 Likes

Glad i found this topic. I’m have the exact same problem - looking forward for the fix.

Thank you! This does indeed fix the issue.

Given that I don’t use “replace” for this particular document type, this will be a suitable workaround.

Appreciate your help

Harry