You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Chris Anderson <jc...@grabb.it> on 2008/07/11 21:51:07 UTC

reduce function without return value

I'm implementing a job-pool with CouchDB, and have found a use-case
that the reduce functionality almost-but-not-quite handles perfectly.

I'd like the option to have reduce functions elect not to return
anything (or undefined I guess as they'd look the same to the
interpreter) and have that key be left out of the final group=true
result altogether. Currently the reduction process fails with the
"Cannot encode 'undefined' value as JSON" error.

The idea is that I have a view that calls emit(key,"todo"). A job
runner picks up the keys and runs a job. When the job is complete, the
job runner creates a document which then emits to the same key, but
with value "done". Completed jobs show up in the map as (key, "todo")
next to (key, "done"). Currently I can write a reduce fro group=true
which is always (key, "done") once the job is complete. I'd like to
have a reduce where the "done" keys are completely absent.

Not high-priority (I can just ignore the done keys for now) but it
will be a nice thing to have once I get into a situation where the
majority of keys are done.

I haven't thought through the consequences when group=false, but the
job pool pattern seems a common enough use case to consider.

Is it possible to support this behavior?

-- 
Chris Anderson
http://jchris.mfdz.com