I have some documents in CouchDB of type: "Person" and of type "Account".

For a straight list of all documents of these types I have created the following design document in _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 }); } })"
       }
   }
}

This JSON validates on JSONLint and is accepted when saving the document in Futon's source view.

Futon lists directory_views/all_persons and directory_views/all_accounts as expected in the dropdown. all_persons creates the correct list of documents of type "Person", however all_accounts redirects back to the toplevel All Documents, and lists everything.

Why does all_persons work, but all_accounts fail?

PS. I've experienced this behavior on a number of design documents so far. This example http://kore-nordmann.de/blog/couchdb_a_use_case.html#a-practical-example shows two views in the same design document, so I don't think that you can only have one view per document.

有帮助吗?

解决方案

Try accessing your view directly (ie. outside of Futon) to see if it behaves the same way.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top