mongodbrealmrealm-mobile-platform

MongoDB does't work as expected (Realm.findAll)


I am a beginner in MongoDB Realm. I followed this guide to start(https://www.mongodb.com/docs/realm/sdk/java/quick-start-sync/). This is the implementation to fetch all employees from MongoDB.

val employeeRealmConfig = SyncConfiguration.Builder(
        realmApp.currentUser()!!,
        AppConfigs.MONGODB_REALM_USER_PARTITION_ID
    ).build()
    backGroundRealm = Realm.getInstance(employeeRealmConfig)
    val queryEmployeesTask = backGroundRealm.where<Employee>().findAll()

I printout queryEmployeesTask size but each time I run my application there is a different result printed out and queryEmployeestask size < 25000. I used mongo compas to check database, there are 25000 records for partition AppConfigs.MONGODB_REALM_USER_PARTITION_ID.

I want to get full 25000 records. How can I resolve this problem?


Solution

  • After checking the document carefully, I realized that Employee Object in the client has a different schema with Mongo Atlast schema, after correcting this problem val queryEmployeesTask = backGroundRealm.where<Employee>().findAll() returns the correct value. I hope this can help someone has the same problem with me