Pouchdb 数据库创建 no_db_file

Pouchdb database creation no_db_file

我正在尝试执行以下操作:我有一个本地数据库(使用 PouchDB),我检查用户是否已登录(使用 pouchdb 身份验证登录功能),如果为真,我将区域设置数据库与远程数据库同步.

不幸的是,当我尝试在 CouchDB 上创建一个新数据库时(我想为每个用户创建一个数据库)我总是收到错误 {"error":"not_found","reason": "no_db_file"}。我看到这是 PouchDB 文档 (https://pouchdb.com/guides/databases.html#remote-databases) 中描述的常见错误,但 CORS 已启用,我不知道问题出在哪里。

我的 couchdb 配置是:

我是这样登录的:

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})
    })
 }

有什么问题吗?感谢任何帮助。

谢谢

要在 CouchDB 服务器上创建数据库,您需要是管理员。您可以为此在服务器上创建一个小型自定义 API(例如使用小型节点 http 服务器),或者使用 CouchDB 的 couchperuser 插件。