How to copy from CouchDB to PouchDB?

I created a local CouchDB database and I would like to replicate it to a PouchDB database using JavaScript on a web page running on a local hosting.

With the code below, I get this error:

The origin of http://localhost not valid with Access-Control-Allow-Origin.

Since http:// is removed from REMOTE, I do not get an error, but no documents are displayed as replicated.

Looking at IndexedDB databases from Chrome DevTools, I see that the database was created (but has no documents).

Works in Chrome 29.0.1535.2 canary.

Can I do this locally or do I need to set up a remote CouchDB database and enable CORS (according to Docs Docs )?

 var REMOTE = 'http://127.0.0.1:5984/foo'; var LOCAL = 'idb://foo'; Pouch(LOCAL, function(error, pouchdb){ if (error) { console.log("Error: ", error); } else { var db = pouchdb; Pouch.replicate(REMOTE, LOCAL, function (error, changes) { if (error) { console.log('Error: ', error); } else { console.log('Changes: ', changes); db.allDocs({include_docs: true}, function(error, docs) { console.log('Rows: ', docs.rows); }); }}); } }); 
+7
source share
1 answer

You can do this locally, but CORS must be enabled.

When you remove "http: //" from the remote URL, Pouch is going to replicate your database to a new Pouchdb with an indexed index named "localhost" (or actually "_pouch_localhost" or something like that - it adds a prefix).

If you are not shipping this page from CouchDB itself (on the same host and port), you need to enable CORS for replication to CouchDB.

+10
source

All Articles