incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Anderson" <>
Subject reduce function without return value
Date Fri, 11 Jul 2008 19:51:07 GMT
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

View raw message