The values passed as newDoc
, and oldDoc
parameters to validate_doc_update
function are Javascript objects: you compare two documents as you compare any JS objects. There no "CouchDB field".
You can write custom code, or you can use a JS library like Underscore.js. You can include it as a CommonJS module. The only problem is the _rev
field. My approach is to keep CouchDB metadata separate from document data, by putting the data in a data
field. For example:
{ "_id": "ID", "_rev": "REV", "foo": "bar", "baz": [1, 2] }
becomes
{ "_id": "ID", "_rev": "REV", "data": { "foo": "bar", "baz": [1, 2] } }
Then the comparison can be done with
function(newDoc, oldDoc) {
var _ = require("underscore");
if (!_.isEqual(newDoc.data, oldDoc.data)) {
// something changed...
}
}