【发布时间】:2019-12-26 01:21:40
【问题描述】:
我正在尝试执行以下操作:我有一个本地数据库(使用 PouchDB),我检查用户是否已登录(使用 pouchdb-authentication 登录功能),如果为真,我将本地数据库与远程数据库同步。
不幸的是,当我尝试在 CouchDB 上创建一个新数据库(我希望每个用户都有一个数据库)时,我总是收到错误 {"error":"not_found","reason":"no_db_file"}。我看到这是 PouchDB 文档 (https://pouchdb.com/guides/databases.html#remote-databases) 中描述的常见错误,但 CORS 已启用,我无法弄清楚问题出在哪里。
我的登录方式如下:
var user = {
name: 'name',
password: 'password'
};
var url = "http://ip/";
var pouchOpts = {
skipSetup: true
};
var ajaxOpts = {
ajax: {
headers: {
Authorization: 'Basic ' + window.btoa(user.name + ':' + user.password)
}
}
};
var db = new PouchDB(url+'auth', pouchOpts);
db.login(user.name, user.password, ajaxOpts).then(function() {
return db.allDocs();
}).then(function(docs) {
//HERE I TRY TO CREATE THE NEW DATABASE
pouchDBService.sync(url+"newDatabase", user);
}).catch(function(error) {
console.error(error);
});
而且,在我的 pouchDBService 中,我有:
var database;
//I call this function as app starts
this.setDatabase = function(databaseName) {
database = new PouchDB(databaseName, {
adapter: 'websql'
});
}
this.sync = function(remoteDatabase, user) {
var remoteDB = new PouchDB(remoteDatabase, {
auth: {
username: user.name,
password: user.password
},
skip_setup: true //without this I get the login popup! Why if I'm passing the auth params???
});
remoteDB.info().then(function (info) {
console.log(info);
database.sync(remoteDB, {live:true, retry: true})
})
}
有什么问题吗?任何帮助表示赞赏。
谢谢
【问题讨论】:
标签: javascript database couchdb pouchdb