Hello,
I am trying to migrate our existing project from realm java to realm kotlin sdk and I am stuck in a pretty weird situation. I have the following structure:
class MyRealmObject() : RealmObject {
@PrimaryKey
var id: Long? = null
[other fields]
}
Given a list of ids, I want to query all MyRealmObject
entries whose ids are not in that list. For that, I am using the following query:
val oldItems = query<MyRealmObject>("id == NONE $newIds").find()
,
where newIds
is a String built from a list of Long ids and it looks something like this: {'23805', '21403'}
.
The query from above works fine if the list of ids has at least 2 elements, but if the list has only one id, then the query returns all entries from the table. This seems to happen only for fields marked with @PrimaryKey annotation. If I remove the annotation, then the query works fine regardless of the list size.
I’ve searched through the topics, also read the documentation from here: https://www.mongodb.com/docs/realm/realm-query-language/ but I couldn’t figure out why this is happening. Am I missing something or could this be a bug in realm kotlin sdk? I am using version 1.10.2
.
As a temporary workaround I add a dummy element to the list of ids, to make sure that I always have at least 2 elements, and this seems to work. But, of course, I don’t want to rely on this and would like to implement a proper solution instead.
Thanks in advance for any help!