title: Populating a new PouchDB database efficiently
body: <p>I am new to PouchDB and I am trying to simply pull data from my remote CouchDB database to a new local PouchDB database.</p>
  <p>The following works of course:</p>
  <pre><code>PouchDB.replicate(remote, local, { live: false, retry: false })
  </code></pre>
  <p>but it is just crazy how slow it is! I take it is because it's doing so many http requests sequentially.</p>
  <p>As an optimisation I thought:</p>
  <blockquote>
  <p>OK, let's fetch the data first in one HTTP request with <code>remote.allDocs</code> then use <code>local.bulkDocs</code> to insert the docs in the local db</p>
  </blockquote>
  <p>but it's not equivalent to replicating the db, and the <code>_rev</code> field in the docs will make <code>bulkDocs</code> fail.</p>
  <p>What should I do?</p>
  <h2>More details</h2>
  <h3>about the database</h3>
  <ul>
  <li>there currently are 1202 documents</li>
  <li>there use to be about 4000</li>
  <li>I just added a couple of revisions to each document</li>
  </ul>
  <h4>about the performances:</h4>
  <ul>
  <li>it takes about 2 seconds to run <code>remote.allDocs({include_docs: true})</code>. The output is 1.15 MB</li>
  <li>it takes <strong>1 minute</strong> to run <code>PouchDB.replicate(remote, local, { live: false, retry: false })</code>, the output is about 5 MB</li>
  <li>it takes about 24 seconds to add a <code>filter: doc =&gt; !doc._deleted</code></li>
  <li>and about 20 seconds to add a <code>filter: 'new_device/excludeDeletedDocs'</code> with the same filter as before in a design document</li>
  </ul>
  <p>About the replication lasting 1 minute: it surprised me, I thought it was faster than that, but it's how long it takes now.</p>
  <h3>about the app</h3>
  <ul>
  <li>there is one database per user</li>
  <li>they can access it through multiple devices, online and offline</li>
  <li>most docs are small, are edited a couple of times and are relatively short lived</li>
  <li>a big minority of them last virtually forever</li>
  <li>a fraction of them can be bigger and can be edited many many times.</li>
  </ul>