It was mentioned by @Ian_Ward a few years ago that MongoDB device sync will add a feature to automatically pull in relationships on subscriptions. Has this feature been implemented yet if so can someone point me to some docs on how to use it?
Thanks
This feature has not been implemented and the workarounds mentioned in the link are your best option. Also checking that you have seen the embedded objects documentation which are synchronised with flexible sync (from MongoDB Atlas perspective they are included in the document):
Hi @otso I understand you can embed objects but where Im confused is when it comes to fetching linking objects.
As say you have the following schema
class Group: Object, ObjectKeyIdentifiable {
@Persisted(primaryKey: true) var _id: ObjectId
@Persisted var owner_id: String
@Persisted var latest_content: List<Content>
@Persisted var members: List<String>
//Other values omitted for simplicity
}
class Content: Object, ObjectKeyIdentifiable {
@Persisted(primaryKey: true) var _id: ObjectId
@Persisted var created_at: Date = Date()
@Persisted var owner_id: String
@Persisted var image_id: String
@Persisted var group_id: Group?
}
A User can be a member of a group but there doesn’t seem to be an easy way of fetching the latest content for that group as there is not really a link between them (note that Content does have owner_id but group members should be able to view posts from other members as well not just there own). So how would I go about solving this ? Am I missing something ?
The same workaround as in the post you link to would work here:
You’ll need subscriptions both for Group and Content and in the subscription you’ll be referring to a field in Content which contains the _id of the Group
Similar setup in code is in the example linked, RChat, see also this blog entry. Have a look at how a ChatMessage is related to Conversation and how the subscription is defined in ChatRoomBubblesView.
In the RChat example, the User embeds the Conversations allowing sharing of messages between the group members.