Skip to content

Conversation

@jcoglan
Copy link
Contributor

@jcoglan jcoglan commented Jan 9, 2026

Overview

This PR implements "phase 1" of the functionality outlined in #5792, i.e. it adds the ability for validate_doc_update to be implemented as a Mango selector expression, rather than as a JavaScript function. The selector is evaluated against an ephemeral JSON structure containing newDoc (the new doc version to be saved) and oldDoc (the one currently on disk). For example, saving the following to /db/_design/mango-vdu will cause all docs to be checked for a type field which must be a string:

{
  "language": "query",

  "validate_doc_update": {
    "newDoc": {
      "type": { "$type": "string" }
    }
  }
}

This uses the existing infrastructure of couch_query_servers and mango_native_proc, just adding appropriate message handlers to Mango processes for handling VDU requests.

Testing recommendations

The added tests cover the basic functionality to check that Mango validators can be saved, and the in-memory cache is updated as appropriate. It assumes Mango works as it does in current releases and so does not re-test all the Mango functionality in detail.

Since there are now two different languages VDUs can be written in, I may have missed anything that assumes there's only one way to do it. I did however notice a counter being updated incorrectly, which is now fixed.

Related Issues or Pull Requests

Checklist

  • Code is written and works correctly
  • Changes are covered by tests
  • Any new configurable parameters are documented in rel/overlay/etc/default.ini
  • Documentation changes were made in the src/docs folder
  • Documentation changes were backported (separated PR) to affected branches

This counter is incremented whenever a VDU returns a value other than
`1`, whereas `ok` and `true` are also treated as acceptable success
values. This fixes the counter to only increment on actual failure
responses.
@nickva
Copy link
Contributor

nickva commented Jan 9, 2026

This is fantastic, much smaller than expected. Nicely done, James!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants