Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The last evaluated expression in the script (eg you don't "return val;" you just end the script "val;"), which can be a string, an object, or an array of objects is placed in a metadata field called "_PERSISTENT_".

...

Preserving Metadata

The following code saves the entirety of the old document's metadata:

...

Code Block
 "onUpdateScript": "var retVal = _old_doc.metadata; retVal;"}
// RESULT (IN THE CASE OF A DOCUMENT THAT DOESN'T CHANGE):
{
    // Usual document fields
    "metadata": {
        "test1": "test",
        "test2": { "field": "value" },
        "_PERSISTENT_": [{
            "test1": "test",
            "test2": { "field": "value" },
        }]
    }
}

...

Generating New Metadata

...

In this example, the return value will represent the delta of the two documents under comparison.

...