Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does updating a design document in couchdb cause rebuilding of views?

Tags:

couchdb

Suppose I have a design document with views, update functions etc. Now suppose I update the design document by adding a validation handler. Will this cause the views defined in this design document to be rebuilt even if I do not make any changes to the view function at all.

like image 830
Akshat Jiwan Sharma Avatar asked May 10 '14 17:05

Akshat Jiwan Sharma


2 Answers

No, the views are not regenerated as long as the views property itself is not changed. CouchDB calculates a hash over the views property of the design document and uses this hash as the filename of the view.

We use this feature a lot in production: We regularly update our design documents, and as long as the views themselves do not change the views are not regenerated.

BTW: This is also the reason why you can use CommonJS modules and require() in views, but you are restricted to paths within views. You can do this for example:

{
  ...
  "views": {
    "lib": {
      "underscore": "... (underscore.js here)"
    },
    "my_view": {
      "map": "function (doc) { var _ = require('views/lib/underscore'); emit(doc._id, _.pick(doc, 'name', 'address'); }"
    }
  }
}

But you cannot use a require like this: var _ = require('underscore');

Hope this helps!

like image 181
Bernhard Gschwantner Avatar answered Oct 18 '22 20:10

Bernhard Gschwantner


Yes. As documented in View API ("Altering/Changing Views" section) in Wiki:

To change a view or multiple view just alter the design document (see HttpDocumentApi) they are stored in and save it as a new revision. This causes all the views in that design document to be rebuilt on the next access in case the view code has been changed.

Note the documentation refers to updating design document not its fields.

like image 36
Marcin Skórzewski Avatar answered Oct 18 '22 18:10

Marcin Skórzewski