I've got ctime
and mtime
(created/modified time) fields in my docs.
How can I let couchDB handle those for me? For example:
// Create a dog
curl -X POST http://localhost:5984/dogs -d '{"name": "Bill"}'
{"ok":true,"id":"75efaeb93aa2ed75ffa0abf9f5006d40","rev":"1-49ce25e3db701c8cb613c1fd18d99619"}
-> ctime
and mtime
should be auto-generated
// Update a dog
curl -X PUT http://localhost:5984/dogs/75efaeb93aa2ed75ffa0abf9f5006d40?rev=1-49ce25e3db701c8cb613c1fd18d99619 -d '{"name": "BILL"}'
-> mtime
should be updated automatically
I was hopping using validate_doc_update
to deal with this, something like:
function (newDoc, oldDoc, userCtx) {
//
// sanity checks
//
if (oldDoc && newDoc.ctime) throw {"forbidden": "ctime cannot be changed!"}
...
//
// Auto-generate fields
//
var now = new Date().toISOString();
// mtime
newDoc.mtime = now;
// ctime
if (!oldDoc) newDoc.ctime = now;
}
but with no luck: it appears altering newDoc
has no effect (pass by copy?)
Thank you