Cloudant's CouchDB + PouchDB => Offline usage

Hello,
I am in the process of developing a desktop application based on Meteor. The app is meant to function both online when the server is reachable, and offline when not, in which case, I was meaning to use PouchDB as a local backdrop, then taking advantage of its sync capabilities, sync everything the moment the client is able to reach the server again. To give you some context for you to understand where I come from, here:

The app (client) is meant to function inside a local network, where one of the computers acts as the server (with a CouchDB server). Whenever one or multiple clients are connected they primarily use their own local PouchDB, which in turn is synced live to CouchDB. When offline, clients can still use the app until such moment they can contact the server again and sync their changes (sync conflicts here are irrelevant, let’s just assume there aren’t).

And so, this is my inquiry: How would I go about implementing that, while still retaining Meteor’s core feature – that is reactive data. Keeping in mind that clients should preferably use their own local storage (PouchDB) which is synced live to the server (CouchDB)

And in case the above is impossible, is there any other alternative for what I am attempting? That is offline usage and seamless sync of data to the server.

Also, somewhat of a side-note, given that I have no control over the network configuration (and thus IPs) my server’s IP may change daily. Cloudant’s docs specify that you need to start Meteor while passing an environment variable which is the server credentials: Isn’t there some way to pass those after the app has started, in this fashion:

Meteor.startup( () => {
   //Find my IP using a personal script
   //Set CouchDB's URL

   ....

  //Sync PouchDB to it
}

Thank you for your time.
Good evening to all.

Hi. Any progress with what you were attempting? I need to store data offline and still not sure what’s the best approach to integrate with Meteor.

Nope, sorry. After much search there is no ready-made solution, one would have to create a viable system from the ground up, which I didn’t have time for. I had to resign myself to having a simple CouchDB connection and force disconnect my clients if their connection failed.

Thanks for the reply. I actually got it working and it was quite easy I might say. I used groundDB: https://github.com/GroundMeteor/db

client/main.js

Meteor.startup(function () {
    // Client Persistent Collections
    localCollection = new Ground.Collection('local-collection');
    localCollection.observeSource(RemoteCollection.find());
    Meteor.subscribe('remote-collection-publish');
});

Now you can use localCollection like you would any other Meteor.Collection. It should sync between client and server.
Just note that, in my case, I just need them to execute the initial sync because the collection don’t change.
I use it for two collections which are quite big (together both have 4MB). I was amazed on how fast it and well it worked.

I also setup Meteor’s AppCache http://docs.meteor.com/packages/appcache.html which seems to work well but later disable it because my cache is WAY over 5MB. I’ll turn on back later when it’s ready to deploy.

That’s it. Hope it helps.

1 Like