Search code examples
couchdbdesign-documents

A Good Point to Create Design Documents in CouchDb


I have a CouchDb instance running a peruser database configuration.

Each user database generated (when a user is added to the _users database) needs to have the same design documents with view/list logic etc.

What is the defacto way to add the design documents to the database upon database creation? Is it simply to add them after a successful user creation request? Or is there a more elegant way of doing this in CouchDb?


Solution

  • There is not a mechanism for initialize newly created user databases, you should include it in your user creation logic. If you want to decouple user creation and db initialization, I suggest you to explore the following strategy

    1 - Create a template database and place on it your design documents that should be applied to every user db

    2 - Listen continuously _db_updates endpoint where db level events will be notified. This library can help you.

    3 - When a db that matches the user db name pattern is created, you can trigger a replication from the template database to the newly created database using the _replicate endpoint.