Would anyone be willing to provide a full documentation example on how to write a couchdb design document?
I've never been able to find a proper documentation on that. I'm able to find a list of the available methods, but not how to write them in the design document. For example, the couchdb documentation in this page explains how to use a map function, but it doesn't explain that this function is implemented in the design document the following way:
{
"views": {
"someView": {
"map": "function(doc){ emit(doc.name, doc) }"
}
}
}
There are very sparse information on that in this page but it seems very incomplete to me. For example it doesn't even mention there can be "validate_doc_update" in the structure.
I think a good documentation example would be very useful in the couchdb doc itself in fact.
It could look like the following:
{
"_id": "_design/exampleDesignDocument",
"_rev": "1-11111111111111111111111111",
"views": {
"someView": {
"map": "function(doc){ emit(doc.name, doc) }",
...
}
},
"lists": {
"someList": "function(head, req){ send('<html>hello</html>') }"
}
...
}
This example would display usages of all design documents methods including (but not limited to if I forgot some): view (map, reduce functions...), show, list, update, filter, validate.
CouchDB is a multi-master application released in 2005 and became an Apache project in 2008. It is written in the Erlang programming language.
Design documentation is a collection of documents and resources that covers all aspects of your product design. Documentation should include information about users, product features, and project deadlines; all essential implementation details; and design decisions that your team and stakeholders have agreed on.
Pouchdb docs provide good documentation elements to answer, as well as IBM cloudant, as proposed by @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) { ... }"
}
But this answer can still be improved and completed I think.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With