{"id":8087,"date":"2015-11-26T13:35:31","date_gmt":"2015-11-26T13:35:31","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/11\/26\/how-to-replicate-from-couchdb-to-pouchdb-open-source-projects-pouchdb-pouchdb\/"},"modified":"2022-08-30T15:03:01","modified_gmt":"2022-08-30T15:03:01","slug":"how-to-replicate-from-couchdb-to-pouchdb-open-source-projects-pouchdb-pouchdb","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/11\/26\/how-to-replicate-from-couchdb-to-pouchdb-open-source-projects-pouchdb-pouchdb\/","title":{"rendered":"How to replicate from CouchDB to PouchDB?-open source projects pouchdb\/pouchdb"},"content":{"rendered":"<p>I&#8217;ve set up a local CouchDB database and I&#8217;d like to replicate it to a PouchDB database, using JavaScript in a web page running on localhost.<\/p>\n<p>With the code below I get this error:<\/p>\n<blockquote>\n<p>Origin <code>http:\/\/localhost<\/code> is not allowed by Access-Control-Allow-Origin.<\/p>\n<\/blockquote>\n<p>With <code>http:\/\/<\/code> removed from REMOTE, I don&#8217;t get an error, but no docs are shown as replicated.<\/p>\n<p>Looking at IndexedDB databases from Chrome DevTools, I can see the database has been created (but doesn&#8217;t appear to have documents).<\/p>\n<p>Running in Chrome 29.0.1535.2 canary.<\/p>\n<p>Can I do this locally, or do I need to set up a remote CouchDB database and enable CORS (as per the CouchDB docs)?<\/p>\n<pre><code>var REMOTE = 'http:\/\/127.0.0.1:5984\/foo';\nvar LOCAL = 'idb:\/\/foo';\n\nPouch(LOCAL, function(error, pouchdb){\n  if (error) {\n    console.log(\"Error: \", error);\n  } else {\n    var db = pouchdb;\n    Pouch.replicate(REMOTE, LOCAL, function (error, changes) {\n      if (error) {\n        console.log('Error: ', error);\n      }\n      else {\n        console.log('Changes: ', changes);\n        db.allDocs({include_docs: true}, function(error, docs) {\n          console.log('Rows: ', docs.rows);\n        });\n    }});\n  }\n});\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve set up a local CouchDB database and I&#8217;d like to replicate it to a PouchDB database, using JavaScript in a web page running on localhost. With the code below I get this error: Origin http:\/\/localhost is not allowed by Access-Control-Allow-Origin. With http:\/\/ removed from REMOTE, I don&#8217;t get an error, but no docs are [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-8087","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8087","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=8087"}],"version-history":[{"count":1,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8087\/revisions"}],"predecessor-version":[{"id":8636,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8087\/revisions\/8636"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=8087"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=8087"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=8087"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}