cha*_*eau 6 couchdb couchdb-futon
有人愿意提供有关如何编写 couchdb 设计文档的完整文档示例吗?
我从来没有能够找到合适的文档。我能够找到可用方法的列表,但无法找到如何在设计文档中编写它们。例如,本页的couchdb 文档说明了如何使用 map 函数,但并未说明该函数在设计文档中是通过以下方式实现的:
{
"views": {
"someView": {
"map": "function(doc){ emit(doc.name, doc) }"
}
}
}
Run Code Online (Sandbox Code Playgroud)
这个页面上的信息非常少,但对我来说似乎很不完整。例如,它甚至没有提到结构中可以有“validate_doc_update”。
我认为一个好的文档示例实际上在 couchdb 文档本身中非常有用。
它可能如下所示:
{
"_id": "_design/exampleDesignDocument",
"_rev": "1-11111111111111111111111111",
"views": {
"someView": {
"map": "function(doc){ emit(doc.name, doc) }",
...
}
},
"lists": {
"someList": "function(head, req){ send('<html>hello</html>') }"
}
...
}
Run Code Online (Sandbox Code Playgroud)
这个例子将显示所有设计文档方法的用法,包括(但不限于如果我忘记了一些):view (map, reduce functions...), show, list, update, filter, validate。
Pouchdb文档提供了很好的文档元素来回答,以及@xpqz提出的IBM cloudant 。
{
"_id": "_design/exampleDesignDocument",
"_rev": "1-11111111111111111111111111",
"views": {
"someView": {
"map": "function(doc){ emit(doc.name, doc) }",
...
}
},
"shows": {
"someShowFunction": "function (doc, req) { ... }"
},
"lists": {
"someList": "function(head, req){ send('<html>hello</html>') }"
},
"updates": {
"oneUpdateFunc": "function (doc, req) { ... }"
},
"filters": {
"someFilter": "function(doc, req){ if (doc.owner === req.userCtx.name) return true; else return false }"
},
"validate_doc_update": "function(newDoc, oldDoc, userCtx, secObj) { ... }"
}
Run Code Online (Sandbox Code Playgroud)
但是我认为这个答案仍然可以改进和完成。
| 归档时间: |
|
| 查看次数: |
1917 次 |
| 最近记录: |