Hello MongoDB Community!
I hope this message finds you well. I am currently facing a challenge while working with Realm and updating properties within a list of embedded objects.
I have two object schemas, BandMember
and MusicBand
, with the latter containing a list of embedded BandMember
objects. The issue arises when attempting to update the MusicBand
object – while the name
property gets updated successfully, the members
property is saved as an empty array.
Given these two object schemas:
BandMember
export const BandMember: Realm.ObjectSchema = {
name: "BandMember",
embedded: true,
properties: {
_id: {
type: "uuid",
default: () => new Realm.BSON.UUID(Crypto.randomUUID()),
mapTo: "id",
},
name: "string",
otherEmbeddedObjectList: { type: "list", objectType: "OtherEmbeddedObject" },
},
};
MusicBand
export const MusicBand: Realm.ObjectSchema = {
name: "MusicBand",
primaryKey: "_id",
properties: {
_id: {
type: "uuid",
default: () => new Realm.BSON.UUID(Crypto.randomUUID()),
},
name: "string",
members: { type: "list", objectType: "BandMember" },
},
};
Code where we do the update
realm.write(() => {
realm.create(
"MusicBand",
{
_id: 123,
name: "Scorpions",
members: membersArrayList,
},
Realm.UpdateMode.Modified,
);
I have reviewed the documentation and tried various approaches, but none seem to work for updating properties that are a list of embedded objects.
Any insights or suggestions on how to address this issue would be greatly appreciated. Thank you in advance for your help.