2 / 6
Jul 2024

I am using realm kotlin android sdk for my app and using shared realm configuration. When I do any query I returning null always while matching data exists in database

val userId = app.currentUser!!.id val data = realm.query<User>("userId == $0", userId) .first() .find()

above code always return null. Below is config code

sConfig = SyncConfiguration.Builder(app.currentUser!!, setOf(User::class)) .initialSubscriptions { // Define the initial subscription set for the realm ... add(realm.query(User::class,"userId == $0", app.currentUser?.id),"user",true) } .log(LogLevel.DEBUG) .waitForInitialRemoteData() .build() realm = Realm.open(sConfig)

Sync is enabled on backend UI. I can fetch current user custom data like below

app.currentUser!!.app.currentUser!!.refreshCustomData() val data = app.currentUser!!.app.currentUser!!.customDataAsBsonDocument()?.toJson()

but when I try to lookup same user in db it returns null. I also tried giving hardcoded db id but still not luck. Am I missing something?

11 months later

Is the lambda scope defined?

Using the subscription from the initial post: updating to explicitly pass the realm -> parameter?

.initialSubscriptions { realm -> add(realm.query(User::class,"userId == $0", app.currentUser?.id),"user",true) }
12 days later

Hi Cory, I created two collections, where I created documents , which contain text and Images(URL), my app can only retrieve the text but not the Images. in collection 2 I cant retrieve either the text or images.
what might be the problem?