I have setup a Realm App and Atlas database correctly. I activated device sync and developer mode and put read and write access to just “true”. I added some documents to some collections with MongoDB Compass.
Now I try to connect in Android Studio with Java SDK via a user email and password (that I created in the Realm UI). The user gets logged in. Then I initialize Realm etc. and it works. Then I try a symple query on the realm and no data at all gets found. No error, just no data there. It behaves as if the entire realm was empty. I also have Client Reset strategy like this, but it didn’t help. The client just does not get ANY data.
@Override
public void onBeforeReset(Realm realm) {
Log.w("auth", "Beginning client reset for " + realm.getPath());
}
@Override
public void onAfterReset(Realm before, Realm after) {
Log.w("auth", "Finished client reset for " + before.getPath());
}
@Override
public void onError(SyncSession session, ClientResetRequiredError error) {
Log.e("auth", "Couldn't handle the client reset automatically." +
" Falling back to manual client reset execution: "
+ error.getErrorMessage());
// close all instances of your realm -- this application only uses one
dbApp..close();
try {
Log.w("auth", "About to execute the client reset.");
// execute the client reset, moving the current realm to a backup file
error.executeClientReset();
Log.w("auth", "Executed the client reset.");
} catch (IllegalStateException e) {
Log.e("auth", "Failed to execute the client reset: " + e.getMessage());
// The client reset can only proceed if there are no open realms.
// if execution failed, ask the user to restart the app, and we'll client reset
// when we first open the app connection.
Log.e("auth", "Sync error. Restart the application to resume sync.");
}
// open a new instance of the realm. This initializes a new file for the new realm
// and downloads the backend state. Do this in a background thread so we can wait
// for server changes to fully download.
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute(() -> {
Realm newRealm = Realm.getDefaultInstance();
// ensure that the backend state is fully downloaded before proceeding
/*try {
dbApp.getSync().getSession(globalConfig).downloadAllServerChanges(10000,
TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}*/
Log.w("auth","Downloaded server changes for a fresh instance of the realm.");
newRealm.close();
});
// execute the recovery logic on a background thread
try {
executor.awaitTermination(20000, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
})
The client reset also works but still, I don’t get any data.