Is there an obvious method I’m missing?
I have these Read only realms for a scavenger hunt object with embedded objects of Tasks, Rules and Hunters.
I have a hunt type object in the user realm that creates the Read only Hunt and the function will update the Tasks and Rules when those are added.
However, unlike creating a trigger for when it is updated in the User realm, copying that change to the shared Read only realm, I need to create and add an embedded object to the hunt when someone joins it.
The Hunter embedded object need to be added (.append in Swift) to Hunt.hunters when someone joins.
Am I missing something obvious? How do I create a function that will add an embedded object to a list in an existing Realm object?
This seems like it should be a straight forward, typical use of Realm and functions, but nothing in the documentation or examples seem to show this functionality.
Or am I wrong and this isn’t/shouldn’t be possible?
Here is a visualization of my data. Blue is the main object, yellow are embedded objects.
Also, a trigger observes a database change in the private Hunt object in the user partition and triggers this function (which is working for the Tasks and Rules lists):
exports = function(changeEvent) {
console.log("changeEvent.fullDocument ", JSON.stringify(changeEvent.fullDocument));
const mongodb = context.services.get("mongodb-atlas");
const masterHunts = mongodb.db("HuntMobDB").collection("Hunt");
var newHunt = { "_id": changeEvent.fullDocument._id + "_shared",
"_partition": changeEvent.fullDocument.code,
"title": changeEvent.fullDocument.title,
"text": changeEvent.fullDocument.text,
"scheduled": changeEvent.fullDocument.scheduled,
"date": changeEvent.fullDocument.date,
"photo": changeEvent.fullDocument.photo,
"code": changeEvent.fullDocument.code,
"maxUsers": changeEvent.fullDocument.maxUsers,
"tasks": changeEvent.fullDocument.tasks,
"rules": changeEvent.fullDocument.rules
};
masterHunts.updateOne({_id: changeEvent.fullDocument._id + "_shared"}, newHunt, {upsert: false});
};
Thanks.
–Kurt