【问题标题】:Error adding docs to CouchDB将文档添加到 CouchDB 时出错
【发布时间】:2018-02-14 21:39:32
【问题描述】:

我的本​​地 PouchDB 文档不会复制到我的远程 CouchDB。

正在同步,因为浏览器下载了我的设计架构,所以这不是权限问题。我认为我的设计架构与我的文档不匹配,但我很难找到编写架构的正确方法。

架构

{
  "_id": "_design/schema",
  "_rev": "4-3d9a49ebffbbd6b7b146240879baa7e4",
  "validate_doc_update": "function(newDoc, oldDoc, userCtx, secObj){ if(userCtx.roles[0] !== 'admin'){throw({forbidden: 'operation forbidden'})} }",
  "views": {
    "by_module": {
      "map": "function(doc){ if(doc.type == 'note'){emit(doc.note);} }"
    }
  },
  "schema": {
    "title": "Contact details",
    "description": "A document containing a person's contact details.",
    "type": "object",
    "required": [
      "name",
      "level"
    ],
    "properties": {
      "_id": {
        "type": "string"
      },
      "_rev": {
        "type": "string"
      },
      "application_access": {
        "type": "string"
      },
      "home": {
        "type": "string"
      },
      "home_email": {
        "type": "string"
      },
      "jobtitle": {
        "type": "string"
      },
      "level": {
        "type": "string"
      },
      "mobile1": {
        "type": "string"
      },
      "mobile2": {
        "type": "string"
      },
      "modified": {
        "type": "number"
      },
      "name": {
        "type": "string"
      },
      "work": {
        "type": "string"
      },
      "work_email": {
        "type": "string"
      },
      "_doc_id_rev": {
        "type": "string"
      }
    }
  }
}

文档

{
  "_id": "fcb52b3072e2038647b328c0a700147f",
  "_rev": "1518449239461",
  "application_access": "User",
  "home": "",
  "home_email": "",
  "jobtitle": "Exemplar",
  "level":  "Bronze",
  "mobile1": "0987654321",
  "mobile2": "",
  "modified": 1518449239461,
  "name": "Zachary Zumbeispiel",
  "work": "",
  "work_email": "",
  "_doc_id_rev": "1518449239460::1-ffd3c056614845ada4a68de4793710ac"
}

所以问题是,我的文档是否符合我的架构?还是我的架构错了?

“模式”在 CouchDB 实例上,文档在 PouchDB 中。

【问题讨论】:

  • CouchDB 没有架构。这就是 NoSQL 的全部意义所在。
  • 所以如果我删除架构它会起作用吗?
  • CouchDB 中没有模式。你不能删除不存在的东西。至于解决你的问题,我不知道。您没有提供足够的信息(错误消息等)来诊断。
  • 但是你已经解决了我的问题——所以如果你发布你的评论作为答案,我会接受它(没有任何错误信息可以发布,这就是我感到困惑的部分原因)。
  • 我没有解决你的问题,因为除了解释 CouchDB 没有架构之外,我什么也没做。

标签: json couchdb schema pouchdb


【解决方案1】:

他们现在正在复制,因为我删除了“文档架构”,所以它可以同步和复制。

所以问题是我在某处读到需要向 CouchDB 添加模式,所以我创建了我认为是模式的东西,显然要同步的文档的结构必须相同,所以同步不起作用,因为文档的结构不匹配。

因此@Flimzy 解释架构的整个概念是线轴意味着我删除了“架构”,瞧,PouchDB 和 CouchDB 现在可以同步 - 问题解决了。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多