【问题标题】:sync pouchdb with filtered replication将 pouchdb 与过滤复制同步
【发布时间】:2023-03-03 01:53:02
【问题描述】:

我正在使用 pouchdb 和 couchDb 作为我的第一个离线移动应用程序的数据库。

https://pouchdb.com/2015/04/05/filtered-replication.html

基于上述,我配置了 pouchdb 并与 couchdb 同步。我正在进行基于用户的过滤。当用户注销并再次登录时,db 值可用。最好的设计方法是什么?

有没有可以参考的例子?

configurePouchdb(user) {
var db = new PouchDB('dbname', {adapter: 'websql'});

 var serverSideFilter = {
        _id: "_design/app",
        filters: {
            "by_user": function (doc, req) {
                return doc._id === '_design/app' || (doc.userId != undefined && doc.userId === req.query.userId);
            }.toString()
        }
    };
    db.put(serverSideFilter).then(function (doc) {
        // design doc created!
    }).catch(function (err) {
        // if err.name === 'conflict', then
        // design doc already exists
    });
  db.sync('http://127.0.0.1:5984/dbname', {
        live: true,
        retry: true,
        filter: 'app/by_user',
        query_params: {"userId": user}
    });
    return db;
}

【问题讨论】:

    标签: reactjs couchdb pouchdb


    【解决方案1】:

    据我所知,CouchDB 或 PouchDB 中的视图都没有 req 参数,因为视图只生成一个不会因用户而异的索引。

    正如https://pouchdb.com/2015/04/05/filtered-replication.html 中所说,不建议使用过滤复制来代替正确的身份验证。 PouchDB 的主要提交者之一在https://github.com/nolanlawson/pouchdb-authentication#couchdb-authentication-recipe

    中提供了一个很好的秘诀

    无论如何,PouchDB API 文档中有一个很好的过滤复制指南:https://pouchdb.com/api.html#filtered-replication

    【讨论】:

      猜你喜欢
      • 2014-02-03
      • 1970-01-01
      • 1970-01-01
      • 2017-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多