couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Goodall <>
Subject Re: Reduce to nothing
Date Thu, 05 Feb 2009 17:22:14 GMT
2009/2/5 Paul Davis <>:
> Matt,
> About the best you're going to get with the current implementation
> would be similar to the code that Jeremy posted which in effect
> returns a 'cancelled' value for that item.

Yeah, which leaves you getting everything out and checking the value
instead of the cancelled docs just "disappearing". Not exactly really

>  I did just wake up so I
> might be missing something clever, but I'm pretty sure this is baked
> in because of the incremental calculation stuff.

:nod: I had a feeling it might break things down there but, not
knowing the code, wasn't sure if it was something someone just hadn't
tried yet. I thought removing a key completely might be feasible, but
less sure about multiple emits.

Oh well, it was a fun idea.

- Matt

> HTH,
> Paul Davis
> On Thu, Feb 5, 2009 at 9:33 AM, Matt Goodall <> wrote:
>> Hi,
>> 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
>> operation.
>> 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