I am trying PouchDB with Cordova on an Android phone. Local databases work but attempts to communicate with my remote database at
cloudant.com fail with an error message I can't interpret, including
error.name = "unknown". Where can I find a fully-worked example that works with
cloudant.com databases, including aspects such as authorisation and CORS? Online examples skip this.
Here's the code that fails:
remoteDb = new PouchDB("
https://myaccount.cloudant.com/mmm_test_1/",
{auth: {username: "myusername",
password: "mypassword"}});
var rep = PouchDB.replicate(localDb, remoteDb, {
live: false,
retry: false
}).on('change', function (info) {
console.log('Changed' + info);
/* snip - other events handled here */
}).on('error', function (err) {
console.log('On error: ' + JSON.stringify(err));
});
and the console output is:
On error: {"status":0,"name":"unknown","message":"getCheckpoint rejected with ","result":{"ok":false,"start_time":"2017-03-15T09:52:16.884Z","docs_read":0,"docs_written":0,"doc_write_failures":0,"errors":[],"status":"aborting","end_time":"2017-03-15T09:52:17.160Z","last_seq":0}}
BTW - JSON.stringify(remoteDb) works before the replicate() call but fails afterwards, with "Uncaught TypeError: Converting circular structure to JSON" - i have traced this to remoteDb.taskqueue
I am using pouchdb-6.1.2.js. If I use pouchdb-3.3.0.min.js it also fails but the errors are different:
On error: {"status":500,"name":"unknown_error","message":"Database encountered an unknown error","error":true}
JSON.stringify(remoteDb) works, but remoteDb.name becomes "undefined".
I am able to access my
cloudant.com database with the same username and password - this Node-RED example shows how:
http://flows.nodered.org/flow/411bab7d9872bac32ad1ebba06c14a37