couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeremy Wall <>
Subject Re: Reduce to nothing
Date Thu, 05 Feb 2009 14:44:16 GMT
Can't you just have the map screen out the cancellations? Seems like that's
the most natural spot for the behaviour you want.

Sent from my G1 google phone

On Feb 5, 2009 8:34 AM, "Matt Goodall" <> wrote:


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

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message