【问题标题】:Pouchdb database creation no_db_filePouchdb 数据库创建 no_db_file
【发布时间】:2019-12-26 01:21:40
【问题描述】:

我正在尝试执行以下操作:我有一个本地数据库(使用 PouchDB),我检查用户是否已登录(使用 pouchdb-authentication 登录功能),如果为真,我将本地数据库与远程数据库同步。

不幸的是,当我尝试在 CouchDB 上创建一个新数据库(我希望每个用户都有一个数据库)时,我总是收到错误 {"error":"not_found","re​​ason":"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})
    })
 }

有什么问题吗?任何帮助表示赞赏。

谢谢

【问题讨论】:

    标签: javascript database couchdb pouchdb


    【解决方案1】:

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

    【讨论】:

    • 感谢您的帮助。我认为 couchperuser 将解决我的问题。无论如何,我不明白 PouchDB 应该如何工作,因为我认为没有人会让他的数据库向世界开放。
    • PouchDB 有很多应用。每个用户一个数据库的场景只是许多可能的用途之一。另一种是服务器数据库部分的离线缓存。在这种情况下,您只需使用从服务器到客户端的单向复制。或者要共享公共数据,您只需将所有客户端的数据库同步到单个服务器数据库。无论您有什么要求,都有许多可能的解决方案。有些可以通过将 PouchDb 与 CouchDb 连接来解决,但有些只能通过 Node API 等第三层解决。
    猜你喜欢
    • 2016-12-06
    • 2018-06-11
    • 2015-06-20
    • 1970-01-01
    • 1970-01-01
    • 2016-01-14
    • 2013-12-26
    • 1970-01-01
    • 2016-06-15
    相关资源
    最近更新 更多