Hi,
is it possible to change a document before an insert?
I would like to modify all keys of an object to lower.
Is this possible?
My JavaScript function so far is:
function(newDoc, oldDoc, userCtx) {
var objectKeysToLowerCase = function (origObj) {
return Object.keys(origObj).reduce(function (newObj, key) {
var val = origObj[key];
var newVal = (typeof val === 'object') ?
objectKeysToLowerCase(val) : val;
newObj[key.toLowerCase()] = newVal;
return newObj;
}, {});
}
newDoc = objectKeysToLowerCase(oldDoc);
}
I get the following error message:
Save failed: Expression does not eval to a function. (function(newDoc, oldDoc,
userCtx) { var objectKeysToLowerCase = function (origObj) { return
Object.keys(origObj).reduce(function (newObj, key) { var val = origObj[key];
var newVal = (typeof val === 'object') ? objectKeysToLowerCase(val) : val;
newObj[key.toLowerCase()] = newVal; return newObj; }, {}); } newDoc =
JSON.stringify(objectKeysToLowerCase(oldDoc)); })