I would like to have a local to the browser DB which updates itself from a remote source. Am attempting to use pouchdb / cloudant to solve this. The remote DB is used by many clients so should be read only and not require authentication. In cloudant my permissions config for relevant db (e.g. "remoteDB") is as follows:
{"cloudant":{"admin_user":["_writer","_admin","_replicator","_reader"],"nobody":["_reader"],"apiKey":["_writer","_admin","_replicator","_reader"]}}
In my setup code I have the following:
var localDB = new PouchDB('local');
var remoteDB = new PouchDB('https://account.cloudant.com/remoteDB');
localDB.replicate.from(remoteDB, {live: false}).on('change', function (change) {
console.log("change", change);
}).on('error', function (err) {
console.log("err-replicate", err);
});
I am getting a 401 unauthorised error when loading a page which includes this. The request that causes this is a PUT request for:
https://account.cloudant.com/remoteDB/_local/JqXQso2dZEjdZsU1e_2Qxw==
The header params are:
- _id: _local/JqXQso2dZEjdZsU1e_2Qxw==
- last_seq: "0"
If I have the nobody user in cloudant for this DB have writer permission the error goes away. Any ideas what is wrong here?
Is this the right way to have oneway replication from a remote source?