将文档添加到 CouchDB 时出错
Error adding docs to CouchDB
我的本地 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"
}
所以问题是,我的文档是否符合我的架构?还是我的模式有误?
"schema" 在 CouchDB 实例上,文档在 PouchDB 中。
他们现在正在复制,因为我删除了 "document schema",所以它可以同步和复制。
所以问题是我在某处读到我需要向 CouchDB 添加模式,所以我创建了我认为是模式的东西,显然要同步的文档的结构必须相同,所以同步不起作用,因为文档的结构不匹配。
因此 @Flimzy 的解释是模式的整个概念是线轴,这意味着我删除了 "schema",瞧,PouchDB 和 CouchDB 现在可以同步 - 问题解决了。
我的本地 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"
}
所以问题是,我的文档是否符合我的架构?还是我的模式有误?
"schema" 在 CouchDB 实例上,文档在 PouchDB 中。
他们现在正在复制,因为我删除了 "document schema",所以它可以同步和复制。
所以问题是我在某处读到我需要向 CouchDB 添加模式,所以我创建了我认为是模式的东西,显然要同步的文档的结构必须相同,所以同步不起作用,因为文档的结构不匹配。
因此 @Flimzy 的解释是模式的整个概念是线轴,这意味着我删除了 "schema",瞧,PouchDB 和 CouchDB 现在可以同步 - 问题解决了。