2 / 2
Aug 2024

Using realm, what is the correct way to filter based on a models sub field? I have a model that as a property that is a list of ObjectId and i want to filter models based on them having a particular id This is what i have but i get an error RealmException: Unsupported comparison operator 'contains' against type 'objectId', right side must be a string or binary type. Error code: 1009.

final query = realm.query<realm_models.Bookmark>( r'collections CONTAINS $0', [ObjectId.fromHexString(id)]);
2 months later

I’m having this same issue and error in realm kotlin doing:

fun Realm.ownedAndParticipatingTrackings(userId: ObjectId) = this.query<Tracking>( query = "ownerId == $0 OR participantIds CONTAINS $0", args = arrayOf(userId), )