How to upgrade a local realm to a synced realm? - realm

The alternative title is "How to sync an offline local default realm?"
The default realm is used to allow the app to be used entirely offline. Later when the user decided to sign up the data stored in the default realm should be kept and synced.
Is there a way to upgrade a local realm to a synced realm?

After reading the documentation, https://docs.mongodb.com/realm/sdk/ios/examples/sync-changes-between-devices/#open-a-synced-realm-offline. The only option available is to manually copy the data from the local realm to the newly created synced realm after user sign up.
You can copy data from a local Realm Database to a synced realm, but you cannot sync a local Realm Database. You must initialize a synced realm with a sync configuration.
A similar question was asked in the MongoDB community "Upgrading a Default Realm to a Synced Realm and Vice Versa" and a response from the MongoDB team on 5th June 2021 was copying data between sync and non-sync realms is the only option.
To copy data from one realm to another on iOS, How to copy objects from the default local realm to a MongoDB synced realm in iOS?
Relevant Info
realm-js - Copy local realm data to sycned realm
Copy all objects from one Realm to another
Asynchronously copy from one realm to another

Related

Flutter Firestore Offline Database

I have a clarifying question about Cloud Firestore and Flutter:
I am making an app that users can create log entries of sort, which will be saved on Firebase. But they might make up to 30 entries offline, before they have internet connection again.
And I know that Firestore has an offline feature, with which any created documents can be viewed offline because it is saved in the order of logging, and then synced with the database when internet connection is gained. But it is absolutely crucial that these logs cannot be lost in my app before having a chance of uploading it. Is there a way to ensure that my app will not lose this data before connecting to Firebase again, or should I create a Sembast database on the device, and save a copy of everything, and then check that once in a while against the database?
Does Firestore have offline contingency for if the phone's battery dies before it could sync with Firestore?
Or is there another solution I am unaware of?
For Android and iOS, offline persistence is enabled by default.
You don't have to do anything in your code.
Note there is a default cache size of 100 MB. This can be changed though, eg
let settings = Firestore.firestore().settings
settings.cacheSizeBytes = FirestoreCacheSizeUnlimited
Firestore.firestore().settings = settings
Does Firestore have offline contingency for if the phone's battery dies before it could sync with Firestore?
When Firestore's offline persistence is enabled, it stores data that your app has recently read, as well as any pending writes, to a database on the local device or browser. This disk based cache will survive restarts of the app/reloads of the page.
For new version of use below code -
FirebaseFirestore.instance.settings =
Settings(cacheSizeBytes: Settings.CACHE_SIZE_UNLIMITED);

Does firestore keep a copy of the entire cloud database in local disk storage?

I am making an app which uses firestore now. I have enabled persistence. I just wanted to know if Firestore keeps a local copy of the entire cloud database or Just the stuff which is accessed by the app through queries.
The local cache that the Firestore client only contains:
the data that your app has recently listened to, and
a queue of the write operations that the local client has performed, but that haven't been synchronized with the server yet

Does firebase download all data on client devices?

Assuming my rules are setup to user read/write on owned object only, I want to know what data does firebase client (IOS/Android) store in devices? In this example, does it download the data that doesn't belongs to the user as well on the device but just blocked it? or only object owned by user will be downloaded on device.
Is there a way to just have some of the child object saved in the cloud only but not locally? I am worried about the db size getting too large in the devices.
Thanks!
Your Firebase app will only have access to data in the database that the rules permit. Security is handled by the Firebase Realtime Database (not the app) so only data that the user is allowed to access will be downloaded.
In order for your app to work with data stored in the database, it needs to be downloaded to the device. By default, data is cached so that your app still works even if your device temporarily loses its network connection. The app only stores this locally if you enable offline capabilities to allow the app to continue working when no network is available.
Firebase apps automatically handle temporary network interruptions. Cached data is available while offline and Firebase resends any writes when network connectivity is restored.
When you enable disk persistence, your app writes the data locally to the device so your app can maintain state while offline, even if the user or operating system restarts the app.
The Firebase app will automatically handle all of this functionality for you.
The size of the local cache will rarely be large enough to worry about, unless you are storing or downloading huge amounts of data, which is not recommended. If your database is large, you should implement strategies to restrict queries to only retrieve relevant data by filtering or paginating your queries.

How long does the Firebase local cache last in a browser?

I understand that data is cached locally and synced with a server, but it is unclear from the docs how long data is saved on the local machine.
If I quit my browser, do I need to re-download my data the next time I visit the app? Is the local data persisted permanently, syncing with the server-data like a git repository?
Thanks.
While Firebase has offline disk persistence available for the iOS client, there is currently no offline storage out-of-the-box in the browser. If you quit your browser or navigate away from the page, only the user's authentication state / session is persisted while all application data will be re-synced.

Current status of Meteor for offline application

There are some threads on SO that cover this - but most of them are 12 months old. I want to understand if Meteor (and available packages) is currently capable of handling:
An App that runs both online (when there is network connectivity) and offline (when there is not).
Allows changes made while offline to be persisted to the server when online (and the reverse).
Allows the data that is persisted to be stored encrypted on the device and only decrypted when used.
Allows some attribute of the user (application password, or possibly a token generated by the server for each logon) to be used as part of the decryption key. (intent is that if the device is stolen and the screen lock bypassed the data is still "reasonably" safe).
On both IOS and Android, rooted and not.
Quoting my own reply on Reddit:
when you export let's say an apk from Meteor, this is a self contained app? this app connects o a server? does it work offline by default?
Yes, theoretically they will work offline. They do work offline now, but they cannot get new data from the server or execute remote procedures on the server w/o a connection (makes sense, right?).
If you want a fully offline app, you can try to use one of the community packages for the offline data support: https://atmospherejs.com/ground/db

Resources