In my application a user can create Activities
, which for the sake of simplicity just have a name, an id, and a creator, where the creator field is a linked object in the PublicUser
collection. I’m using @realm/react and typescript, so the model looks like this:
export class Activity extends Realm.Object<Activity> {
_id: Realm.BSON.ObjectId = new Realm.BSON.ObjectId()
name: string = 'Unnamed activity'
creator!: PublicUser
static primaryKey = '_id'
}
}
I would like every user to be subscribed to documents in the Activity
collection where they are the creator
. However, this seems to be disallowed, as the PublicUser
is a linked collection. To set up the subscription, all I need is the ID, which is exactly what is stored in the database itself. But Realm only sees a link, as far as I can tell, and there is no way to use the ID itself when establishing a sync subscription.
To get around this, I can duplicate the ID in a separate field, eg
export class Activity extends Realm.Object<Activity> {
_id: Realm.BSON.ObjectId = new Realm.BSON.ObjectId()
name: string = 'Unnamed activity'
creator!: PublicUser
creatorId: Realm.BSON.ObjectId
static primaryKey = '_id'
}
This duplication allows me to establish a subscription on the basis of the creators ID. I plan on using this approach, but I wanted to make sure that I am not missing some way to simply look at the link as an ObjectId
rather than a Link
, as it would be much cleaner. There are several similar cases in my app so I’d rather avoid the duplication strategy if possible.
Thanks,
Brian