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

StackOverflow https://stackoverflow.com/questions/23584218

  •  19-07-2023
  •  | 
  •  

سؤال

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.

هل كانت مفيدة؟

المحلول

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!

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top