You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CouchDB复制无法同步旧版本文档问题求助

CouchDB 3.2.2 过滤复制无法同步历史文档问题

基于CouchDB replication实现单用户单数据库系统,通过selector根据用户配置过滤数据,此前方案运行稳定,近期出现异常:

将主库mainDB设为复制源,为用户创建子库subDB作为复制目标。创建带selector的复制文档后,subDB始终为空,复制状态显示「Running」但「0 pending changes」。仅当更新mainDB中符合复制条件的文档(使其_rev变更)时,复制才会触发并将文档同步至subDB。简言之,基于selector的CouchDB过滤复制,需要更新文档的_rev才能同步旧版本文档。

使用版本:Apache CouchDB v3.2.2


补充信息1:原始Selector示例

{
   "selector": {
        "$or": [
            {
                "date_debut": {
                    "$lte": "#end_date#"
                },
                "typedoc": "ActiviteDocument",
                "date_fin": {
                    "$gte": "#start_date#"
                },
                "id": {
                    "$in": [
                        #array_of_integer_A#
                    ]
                }
            },
            {
                "typedoc": "IndividuDocument",
                "id": {
                    "$in": [
                       #array_of_integer_B#
                    ]
                }
            }
            // 其余$or部分逻辑一致,JSON过长未完全展示
        ]
    }
}

补充信息2:调整后的Selector($or与$and组合)

{
    "selector": {
        "$or": [
            {
                "$and": [
                    {
                        "typedoc": "ActiviteDocument"
                    },
                    {
                        "date_debut": {
                            "$lte": "#end_date#"
                        }
                    },
                    {
                        "date_fin": {
                            "$gte": "#statt_date#"
                        }
                    },
                    {
                        "id": {
                            "$in": [#array_of_integer_A#]
                        }
                    }
                ]
            },
            {
                "$and": [
                    {
                        "typedoc": "IndividuDocument"
                    },
                    {
                        "id": {
                            "$in": [#array_of_integer_B#]
                        }
                    }
                ]
            }
        ]
    }
}

补充信息3:改用doc_ids配置复制,问题依旧

{
  "_id": "replicationmaster-1123",
  "source": "mysource",
  "target": "mytarget",
  "doc_ids": [
    "ActiviteDocument_335765",
    "ActiviteDocument_351882",
    "ActiviteDocument_421350",
    "ActiviteDocument_423684",
    "ActiviteDocument_428304",
    "ActiviteDocument_440523",
    "ActiviteDocument_442048",
    "ActiviteDocument_443727"
  ],
  "continuous": true,
  "create_target": false,
  "owner": "admin"
}

补充信息4:问题演示说明

已录制问题演示视频,直观展示复制仅在文档_rev变更后才触发同步的现象。


内容的提问来源于stack exchange,提问作者NLF.Noorlink

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 10:55:21