为什么这些CouchDB视图中只有一个有效?

时间:2012-05-17 07:55:25

标签: json couchdb couchdb-futon design-documents

我在CouchDB中有一些类型为"Person"且类型为"Account"的文档。

对于这些类型的所有文档的直接列表,我在_design/directory_views中创建了以下设计文档:

{
   "_id": "_design/directory_views",
   "_rev": "21-f5df9253504e66f28393f4bda360e110",
   "views": {
       "all_persons": {
           "map": "(function(doc) { if (doc.type == \"Person\") { emit(null, { 'last_name': doc.last_name, 'first_name': doc.first_name }); } })"
       },
       "all_accounts": {
           "map": "(function(doc) { if (doc.type == \"Account\") { emit(null, { 'username': doc.username }); } })"
       }
   }
}

此JSON在JSONLint上验证,并在Futon的源视图中保存文档时被接受。

蒲团在下拉列表中按预期列出directory_views/all_personsdirectory_views/all_accounts。 all_persons创建"Person"类型的正确文档列表,但all_accounts重定向回顶层All Documents,并列出所有内容。

为什么all_persons有效,但all_accounts失败?

PS。到目前为止,我已经在许多设计文档中遇到过这种行为。此示例http://kore-nordmann.de/blog/couchdb_a_use_case.html#a-practical-example在同一设计文档中显示了两个视图,因此我认为每个文档只能有一个视图。

1 个答案:

答案 0 :(得分:1)

尝试直接访问您的视图(例如,在Futon之外)以查看其行为是否相同。

相关问题