couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brad Anderson <>
Subject nested docs / comments view
Date Fri, 29 Feb 2008 04:40:01 GMT

I'm trying to use recursion in a view... maybe.

Actually, I'm trying to use one GET to retrieve a document and its  
(possibly nested) snippets.

{_id: "TestDoc", type: "doc", title: "Test Title"}

{_id: "snip1", type: "snip", parent: "TestDoc", contents: "...",  
order: 1}
{_id: "snip1a", type: "snip", parent: "snip1", contents: "...", order:  
{_id: "snip1b", type: "snip", parent: "snip1", contents: "...", order:  
{_id: "snip2", type: "snip", parent: "TestDoc", contents: "...",  
order: 2}

So, I tried cmlenz's blog post with View Collation (

), but it only did one level.  I like the approach of the snippets  
being their own docs, because I think (hope) the update volume on  
those will be high.

I'm wondering if there are other goodies like map() available in view  
functions.  Will I need to call this()?  Should I have the child doc /  
snip keep track of its parent's ids as I've laid out above?  It seems  
like this might lead to a lot of calls instead of the single call I  
want to make.

It just doesn't feel right to have the parents keep track of its  
children's ids, for chance of orphaning, maint. nightmares, and more.   
Who knows, maybe it's a better approach.  Even if I take that route,  
when iterating thru the children of a doc, how do I recursively call  
the function?  Can there be subfuns in Javascript (well, CouchDB views)?

Or a totally new approach is warranted?


View raw message