鉴于 CouchDB 中的以下文档....
{
"_id": "002bafd55b353692a7ab2968074310cc2cbff258",
"_rev": "1-bc853056ac61d817ae3c4ecb4f81322b",
"names": [
{ "locale": "en", "value": "Example" },
{ "locale": "de", "value": "Beispiel" },
{ "locale": "fr", "value": "Exemple" }
],
"details": [
{ "locale": "en", "value": "An Example is here" },
{ "locale": "de", "value": "Ein Beispiel ist heir" }
{ "locale": "en", "value": "Un exemple est ici" }
]
}
...我如何编写一个视图,允许我返回一个过滤掉不需要的语言的部分文档?
curl ..snip.. '_design/locale_filter/?locale=en,de,fr,it'
curl ..snip.. '_design/locale_filter/?locale=en,fr'
curl ..snip.. '_design/locale_filter/?locale=en'
应该返回如下所示的内容:
{
"_id": "002bafd55b353692a7ab2968074310cc2cbff258",
"_rev": "1-bc853056ac61d817ae3c4ecb4f81322b",
"names": [
{ "locale": "en", "value": "Example" },
],
"details": [
{ "locale": "en", "value": "An Example is here" },
]
}
还有一个子案例,其中文档具有更深层次的结构,重复名称和详细信息结构,这些也将在理想世界中被过滤:
{
"_id": "002bafd55b353692a7ab2968074310cc2cbff258",
"_rev": "1-bc853056ac61d817ae3c4ecb4f81322b",
"names": [ ... snip ... ],
"details": [ ... snip ... ]
"deeper": {
"names": [
{ "locale": "en", "value": "Sub-Example" },
],
"details": [
{ "locale": "en", "value": "The Sub-Example is here" },
}
}
我还注意到,这可能不是一个视图,而是一个节目,从文档 couchdb 中说,一个节目用于将文档转换为任何格式。
初学者的最后一个问题是是否有某种方法可以更轻松地处理 couchdb 视图和设计文档,现在我正在尝试使用 erica,这感觉有点矫枉过正,因为我很确定我不想要沙发应用程序,我只想轻松地在磁盘上的文件中维护我的视图,并在我进行了足够大的更改时将它们与沙发数据库同步。