wohali commented on issue #1554: Additional Mango-based update handler / VDU 
URL: https://github.com/apache/couchdb/issues/1554#issuecomment-412322522
   Got to thinking more about this one in the shower. Here's a sample 
Mango-like document structure for a combined VDU/update handler that would 
capture all of the above:
     "queries": [
         "name": "sensor_name",
         "selector": {
           "type": "sensor",
           "ip_address": "$doc.ip_address"
         "fields": ["name"],
     "fields": {
       "whitelist": ["type", "datetime", "ip_address", "station_name", 
"temperature", "RH%", "rain_gauge", "wind.speed", "wind.direction", "light", 
"battery.voltage", "battery.current", "line.voltage", "line.current", 
"solar.voltage", "solar.current", "register_total"],
       "blacklist": ["battery.wattage", "rain_gauge.*"],
       "formats": {
         "type": ["sensor_reading"],
         "datetime": {
           "$or": {
             "$format": "$iso8601",
             "$format": "$unixepoch",
             "$regex": "(\\d{2})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})"
         "battery.voltage": "$float",
         "battery.current": "$float",
         "register_total": { "$regex": "^\\$\\d{1,9}\\.\\d{2}$" },
         "wind.direction": {"$or": ["N", "NE", "E", "SE", "S", "SW", "W", "NW"]}
     "patch": [
         { "op": "add", "path": "/", "value": { "name": 
"$query:sensor_name.name" } },
         { "op": "move", "from": "/ip-address", "path": "/ip_address" },
         { "op": "add", "path": "/", "value": { "server_datetime": 
"$server_time.iso8601 } },
   * This runs a Mango query up front to get any documents with `"type": 
"sensor"` that match the IP address of the incoming request. (Assumes that the 
`$req` object has that value, not sure we pass that thru to VDUs right now...)
   * There's then a field presence check. In a real situation, you would 
probably only have one of `fields.whitelist` and `fields.blacklist`.
   * Field values/formats are then checked, some just for general structure, 
one by regex, one by list of acceptable values. The output of a Mango query 
could be used as input to this, too. (An aside: Mango aggregations could be 
really useful here, for instance to reduce a query to a single list of 
acceptable values. See #1254.)
   * Documents that didn't match `"type": "sensor_reading"` or any of the other 
format checks would fall through to the next whatever-we-call-this-thing. If 
all failed, the document would be rejected.
   * Maybe we add a `"$format": "$datetime"` that includes all the common 
datetime formats?
   Just some food for discussion.

This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:

With regards,
Apache Git Services

Reply via email to