couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Goodall <>
Subject Reduce to nothing
Date Thu, 05 Feb 2009 14:33:26 GMT

Is it possible to reduce a key to nothing, i.e. completely remove a
key from the reduction result.

For instance, say you post three documents:

    {"_id": "thing1", "type": "thing"}
    {"_id": "thing2", "type": "thing"}
    {"_id": "...", "type": "cancellation", "cancels": "thing1"}

It's trivial to produce a map function that collates the "thing" and
"cancellation" documents. However, I can't work out how, or even it
it's possible, to reduce the view that so that only "thing2" remains.

This seems like it might be a useful thing to be able to do at times.
For instance, posting a "cancellation" document effectively removes a
"thing" from the database. Nothing needs to touch the "thing",
avoiding any chance of conflicts and it doesn't matter how many
"cancellation" documents get posted making cancellation an idempotent

I tried not returning anything, just in case it worked ;-), but got a
JSON encoding error (can't encode undefined, iirc). That would be a
simple approach. However, I wondered if the more "normal" approach of
allowing a reduce function to emit zero or more (key, value) pairs
would be even better? Not sure if that would break the incremental
reduce though.

Any ideas, or is there another way to achieve this that I'm missing?

- Matt

View raw message