编写 couchdb 设计文档
Writing a couchdb design document
是否有人愿意提供有关如何编写 couchdb 设计文档的完整文档示例?
我一直没能找到合适的文档。我能够找到可用方法的列表,但找不到如何在设计文档中编写它们。
例如,couchdb documentation in this page说明了如何使用一个map函数,但没有说明这个函数在设计文档中是这样实现的:
{
"views": {
"someView": {
"map": "function(doc){ emit(doc.name, doc) }"
}
}
}
this page 中关于此的信息很少,但对我来说似乎很不完整。例如,它甚至没有提到结构中可以有 "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>') }"
}
...
}
此示例将显示所有设计文档方法 的用法,包括(但不限于,如果我忘记了一些):查看(映射、缩减函数.. .), 显示、列表、更新、过滤、验证.
Pouchdb docs provide good documentation elements to answer, as well as IBM cloudant,由@xpqz 提出。
{
"_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) { ... }"
}
但我认为这个答案还有待改进和完善。
是否有人愿意提供有关如何编写 couchdb 设计文档的完整文档示例?
我一直没能找到合适的文档。我能够找到可用方法的列表,但找不到如何在设计文档中编写它们。 例如,couchdb documentation in this page说明了如何使用一个map函数,但没有说明这个函数在设计文档中是这样实现的:
{
"views": {
"someView": {
"map": "function(doc){ emit(doc.name, doc) }"
}
}
}
this page 中关于此的信息很少,但对我来说似乎很不完整。例如,它甚至没有提到结构中可以有 "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>') }"
}
...
}
此示例将显示所有设计文档方法 的用法,包括(但不限于,如果我忘记了一些):查看(映射、缩减函数.. .), 显示、列表、更新、过滤、验证.
Pouchdb docs provide good documentation elements to answer, as well as IBM cloudant,由@xpqz 提出。
{
"_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) { ... }"
}
但我认为这个答案还有待改进和完善。