I'm trying to create an index on my data, but I keep getting this error. I've removed all permissions from the database temporary to get it work but still no success.
{
error: 'error_saving_ddoc',
reason: 'Unknown error while saving the design document: unauthorized',
ref: 612684199,
status: 500,
name: 'error_saving_ddoc',
message: 'Unknown error while saving the design document: unauthorized'
}
My code:
(async () => {
let db:any = new PouchDB('http://localhost:5984/test', { skip_setup: true });
await db.createIndex({
index: {fields: ['area']}
})
let res = await db.find({
selector: {'area': {$gt: null}},
fields: ['_id', 'area'],
sort: ['_id']
});
})();
I've also tried installing pouchdb-authentication and have successfully logged in using the code below, but I'm still unable to create indexes using the code above.
Auth code:
this.db.logIn('admin', 'password').then((x)=>{
console.log("This works");
}).catch(e=>console.log(e));
What should I try to get this working?
I believe pouchdb-authentication is a complication[1], and there are known issues regarding that plugin[2,3].
I am of the opinion using Basic Authentication over HTTPS is best for most use cases. I see pouchdb-authentication being handy in cases where there is a need to switch credentials often to perform various tasks.
The below code demonstrates different ways to authenticate. This code works with nodejs but is easily adapted for the browser, assuming server side CORS is setup correctly[4].
Do note I altered your find code, as the
sortparameter would break the query.1PouchDB Security
2pouchdb-authentication issue #243
3pouchdb-authentication issue #204
4Add CORS to CouchDB