我尝试在我的数据上建立索引,但是我总是收到这个错误。我已经暂时移除数据库的所有权限,让它运作,但是仍然没有成功。
{
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'
}
我的代码:
(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']
});
})();
我也尝试过安装pouchdb-authentication
,并使用下面的代码成功登录,但我仍然无法使用上面的代码创建索引。
验证码:
this.db.logIn('admin', 'password').then((x)=>{
console.log("This works");
}).catch(e=>console.log(e));
我该怎么做才能让它工作呢?
1条答案
按热度按时间iyzzxitl1#
我认为pouchdb身份验证是一个复杂的问题[1],并且存在关于该插件的已知问题[2,3]。
我的 * 意见 * 是使用HTTPS的基本身份验证是最好的大多数用例。我看到pouchdb-authentication是方便的情况下,有需要经常切换凭据来执行各种任务。
下面的代码演示了不同的认证方式。这段代码可以在nodejs上运行,但是如果服务器端的CORS设置正确,那么它也可以很容易地适应浏览器[4]。
请注意,我修改了查找代码,因为
sort
参数会破坏查询。1 PouchDB安全性
2个
3个pouchdb-authentication issue #204
4个Add CORS to CouchDB