Search code examples
couchdbscale

Does CouchDB limit the number of views per design doc?


I'd like to build an application that creates a new _view for each user of the application. I'm wondering about scale. A a million users (should we be so fortunate) does one long list of views within a design doc still function with some performance?

Update: What I'm trying to accomplish

I've got three types of docs that'll sit in my databse: docs that describe projects, docs that describe users, and docs that describe actions. Each action will belong to one and only one user, and one and only one project. I'll have views (HTML views) for users, their profile pages, and views for projects. So, I'd like to be able to grab all of a given user's actions in one request (a couchdb _view perhaps). I'd also like to be able to grab all the actions taken for a project in one request (another couchdb _view... perhaps).

Update 2 : )

So users will likely update their profiles, adjusting user docs, and project leaders will likely update project information, changing project docs in the db. Actions are permanent and happen once, so no conflicts there.


Solution

  • That only requires two CouchDB views: One that indexes actions by user and one that indexes actions by project. Assuming you have an action document that looks like this:

    {
      "type": "action",
      "project": "someProjectID",
      "user": "someUserID"
    }
    

    You can write a view with the following map function:

    function(doc) {
      if (doc.type == "action") {
        emit(doc.project, null);
      }
    }
    

    Querying the view with include_docs=true and key=someProjectId will return all actions for a given project.