realm / realm-kotlin

Kotlin Multiplatform and Android SDK for the Realm Mobile Database: Build Better Apps Faster.
Apache License 2.0
886 stars 52 forks source link

Can't query by RealmInstant #1657

Closed michaellinder1995 closed 4 months ago

michaellinder1995 commented 4 months ago

How frequently does the bug occur?

Always

Description

Example class in kotlin sdk:

class Workout : RealmObject { /** PROPERTIES */ @PrimaryKey var id: RealmUUID = RealmUUID.random() var created: RealmInstant? = RealmInstant.now() }

Example call (empty result):

val workouts = realm.query(Workout::class, query = “date < $0”, RealmInstant.now()).find()

Sadly i always get an empty result. No matter which direction of the comparison operator I'm using. I did’nt find anything in the documentation how to query Realminstant: https://www.mongodb.com/docs/realm/realm-query-language/ 1

Anyone knows how to create the query or what datatype i should use instead? Currently my workaround would be to query all and then do the filtering with standard Kotlin function. But performance sucks.

Hope anyone can help.

Version

1.12.0

kneth commented 4 months ago

In the class, the field is called created while you use date in the query. Is that a typing mistake?

michaellinder1995 commented 4 months ago

Oh shit :D

I had a second var var date: RealmInstant? = null

That wasn't set. Thanks so much!