1
votes

I have an ionic 3 PouchDB App that works on some Android devices (e.g. 4.4 & 5.0) but not on others (e.g. 7.0.1). It works on all iPhones! I suspect this is due to some Android versions restricting the number of Webview DBs to one per App.

I have read that one can get around this is by using SQLite but SQLite is a lot slower and is particularly slow for DB documents containing images (which I have). So I would like to look at replicating my two CouchDB database to a single PouchDB database.

I have a couple of questions:

  1. Is there any reason why this would not work as a way to get around the Android DB limit? I will have a localDB.replicate.from(remoteDB) for each of my two remote DBs (called 'news' & 'events').
  2. Currently each of my CouchDB databases have documents with IDs like: 2017-1 and 2017-12for the first and last month of 2017. If I have the two DBs replicating into the one PouchDB will they have to have unique IDs? If not how would I differentiate?
1

1 Answers

1
votes
  1. Yes, you can replicate as many dbs into a DB as you like, but documents with the same id should become "eventual conflicts" when replicated into one db, so one document will lose and only be visible in the merged db by explicitly requesting conflicts.

  2. When using non-random ids, you should update at least one of your dbs to use a unique namespace, for example Event-2017-01. This will also simplify the replication filter you would need if you want to implement bidirectional replication with the still separated remote dbs.

I usually give a doc's attachments a separate doc that is prefixed, i.e: attachment-[orig_id] so media can be filtered from replications. You may want to consider resolving attachments this way (for at least one of the dbs) such that you can mix all attachments in one "media" db with the ideal adapter for the given client and use other adapter(s) for normal documents.

So for example, you may have:

  mdb = new Pouchdb('media', {adapter:'idb'}).
      replicate.from('http...news', {filter:'_view', view:'mediadocs'}).
      replicate.from('http...events', ...filter...);
  news = new Pouchdb('news', {adapter:'websql'}).
      replicate.from('http...news', {filter:'_view', view:'normaldocs'});
  events = new Pouchdb('events', {adapter:'websql'}).
      replicate.from('http...events', {filter:'_view', view:'normaldocs'});

If the fields with media are split into another doc based on the original doc you have no redundant copies yet.. But then you can build temporary dbs fed from news and events:

today = new Pouchdb('today', {adapter:'memory'}).
      replicate.from(news, {selector ..dayview..}).
      replicate.from(events, ...selector...);

where the temporary databases use relatively few resources, but their docs serve as indexes to the corresponding media db documents.