简体   繁体   English

PouchDB过滤了来自ouchDB的复制,未过滤

[英]PouchDB filtered replication from couchDB not filtering

Old versions of my app are uploading outdated files to my couchDB database. 我的应用程序的旧版本正在将过时的文件上传到我的couchDB数据库中。 Here is my couchDB design doc for filtering 这是我的ouchDB设计文档,用于过滤

"function(doc, req) {    
  if(doc._id === '_design/app') {
    return true;
  }
  if(doc._id.slice(0, 8) == '_design/') {
    return false;
  }
  if (doc.username === 'localUser' || !doc.username || doc._id == 'databaseversion') {
return false;
  }
}"

As you can see documents that don't have a username are supposed to be excluded. 如您所见,应该将没有用户名的文档排除在外。 But some of them are still replicating. 但是其中一些仍在复制。 Below is how I start the replication in PouchDB. 下面是我如何在PouchDB中启动复制。 Do I need to make vocabcouchdb the src and localdb the target so that the design doc on vocabcouchdb is used to check what to filter before anything else? 我是否需要将vocabcouchdb设置为src,将localdb设置为目标,以便使用vocabcouchdb上的设计文档来检查要过滤的内容,然后再进行其他操作?

syncObjWords = PouchDB.sync(localdb, vocabcouchdb, {
        live: true,
        retry: true,
        filter: 'app/reject_other_users_personal_words',
        query_params: {
          'username': $rootScope.globalUserData.username
        }
      }) 

I eventually solved this. 我最终解决了这个问题。 I think it was just old versions of apps on other devices with different syncing rules syncing things they shouldn't. 我认为这只是其他设备上应用程序的旧版本,具有不同的同步规则来同步它们不应该同步的内容。 To fix it I added a syncVersion key to each document. 为了解决这个问题,我向每个文档添加了一个syncVersion键。 Now I can filter by the version so that old installations of the app don't sync things that are outdated. 现在,我可以按版本进行过滤,以便该应用的旧安装不会同步过时的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM