Refreshing Partially Synced Data From Cloud to Local Database




For a partially synced database through Realm Cloud, I’m able to read from Realm Cloud and get objects into my local realm database. So far, so good.

However, if I close the app on my phone/simulator, delete the original object on the remote realm (I delete it through Realm Studio), I would expect the next time I try to retrieve that object (with a remote subscription and everything), that I would get 0 results. However, looks like I always get the original object back (presumably loading from my local realm database). So I’m able to get the latest objects synced to my device from Realm Cloud when they exist, but I’m not getting the latest synced to my device once they’ve been removed.

Update with more info: Also happens for remote edits of, say, text fields within an object. I’m not getting the latest. Here is what I’m using:

    let config = syncUser.configuration(realmURL: Constants.GLOBAL_REALM_URL)
    let realm = try! Realm(configuration: config)
    let results = realm.objects(User.self)
    let subscription = results.subscribe()

    if results.count == 1 {
        print("User already exists in realm User DB, nothing more to do, we're all good.")
    } else if results.count == 0 {
        print("User not found in database.")

What am I missing??

Many thanks in advance,



It’s just a tip, but I don’t think that the
let realm = try! Realm(configuration: config)
will sync the remote database, it just opens the realm with the config.

I’m not using the partial sync [yet…], but I think the
Realm.asyncOpen(configuration: config, callbackQueue: DispatchQueue.main)
will return only if the data synced to the local database.
Its worth a try :slight_smile:


Yes, looks like you never give the Realm a chance to pull down the remote changes - either use asyncOpen or simply wait some time (a few seconds or so) and you should see the updated/deleted/inserted values.