I'm a little dumbfounded by reduce functions.

What I'm trying to do is take a view that has heterogeneous values and union 
into a single object; logically this seems like what the reduce function should 
be capable of doing, but it seems I keep getting the reduce overflow error. 
Effectively I'm reducing the view by 50%.

Consider the the simplistic scenario:

doc A: { _id : "abc123", type:"resource", keyword:"nasa" }
doc B: { _id : "abc123-timestamp", type: "timestamp", timestamp: 
"2011/05/19T12:00:00.0000Z", ref_doc: "abc123" }
doc N: ....

Doc A is the original doc... Doc B is the timestamp doc referencing Doc A via 
ref_doc field... Doc N is just another doc also referencing Doc A via ref_doc 
field.

I can create a view that essentially looks like:

Key                             Value
------------            ------------------
"abc123"                { .... doc A object .... }
"abc123"                { .... doc B object .... }
"abc123"                { .... doc N object .... }

I would expect I could build a reduced view that looks something like this:

Key                             Value
------------            ------------------
"abc123"                { .... merged doc .... }

Ultimately this goes back to an issue we have where we need the node local 
timestamp of a document, without generating an event that would cause an update 
to doc A, causing it to get replicated. We figure we can store local data like 
a timestamp then join it back with the original doc via a view & list.

Is there something magical about the reduce that's not well documented? Or 
maybe is there a better way to do this?  I know about using linked docs, were 
in my map function you can reference the _id of the linked document in the 
value you can return @ 1 - 1 merge with the include_docs=true, but don't think 
I can do that with N docs; or can I?

Jim Klo
Senior Software Engineer
Center for Software Engineering
SRI International




Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to