incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sean Copenhaver <sean.copenha...@gmail.com>
Subject Re: Inlining Linked Document Data
Date Mon, 24 Oct 2011 12:29:45 GMT
Only existing thing I can think of that could do what you ask is (for your
example) you could have a "docs by user" view with a map like (untested,
just for example):

function (doc) {
    if (doc.type === 'user') {
       emit([doc._id, doc.type]);
       return;
    }

    if (doc.user_id && doc.category_id) {
        emit([doc.user_id, doc.category_id, doc.type]);
    }
}

Then you can do things like get me the user doc and their all the product
docs in CAT001:

?start_key=['USER004']&end_key['USER004', 'CAT001',
'product']&include_docs=true

But this would not retrieve the categories since those are bottom level and
wouldn't have an id to link it back to any of this. Gets you part of the
way, maybe most of the way depending, for related documents though.

On Mon, Oct 24, 2011 at 4:09 AM, Alexander Gabriel <alex@barbalex.ch> wrote:

> this feature would be extremely useful
> Alex
>
> 2011/10/24, Jamie Talbot <jamie@jamietalbot.com>:
> > Hi,
> >
> > With reference to linked documents, is there any support for the idea
> > of linked document data being inlined into an emitted {_id: XXX}
> > block, perhaps with a new query parameter such as 'follow_links=true',
> > rather than being appended when called with 'include_docs=true'?
> >
> > I know this represents a substantial departure from how things work
> > now, but it would offer two significant benefits that I can see:
> >
> > 1)  The ability to follow multiple linked docs from a single document
> > in a single request.  Let's say for a blog post:
> >
> > function (doc) {
> >       emit(doc.timestamp, [{_id: doc.category_id}, {_id: doc.user_id}]);
> > }
> >
> > called with follow_links=true which would return for example:
> >
> > {
> >       "key": 'POST010',
> >       "value": [{
> >               '_id': 'CAT001',
> >               'name': 'First Category'
> >       }, {
> >       '_id': 'USER004',
> >       'name': 'Monkey Magic',
> >       'dob': '1981-02-06'
> >       }]
> > }
> >
> > 2) You could combine it with include_docs=true, and be able to
> > retrieve the source document at the same time.  At the moment when
> > using this, if I want data from the source and the linked doc, I can
> > only retrieve one or the other with include_docs, which either forces
> > me to emit more data from the source, increasing the size of the view,
> > or else avoid using the link and make multiple requests.
> >
> > While currently useful for hierarchies, I find the linked docs feature
> > a little limiting when I want to use it for any other purpose.
> >
> > Thoughts?
> >
> > Are there any existing ways to achieve the above?
> >
> > Cheers,
> >
> > Jamie
> >
> > ---
> > http://jamietalbot.com
> >
>
>
> --
>
>
>
>
> *****************************************************************
>
>
>
> Alexander Gabriel
> Wiesenstrasse 22
> 8800 Thalwil
> 079/ 372 51 64
> alex@barbalex.ch
> ww.barbalex.ch
>



-- 
“The limits of language are the limits of one's world. “ - Ludwig von
Wittgenstein

"Water is fluid, soft and yielding. But water will wear away rock, which is
rigid and cannot yield. As a rule, whatever is fluid, soft and yielding will
overcome whatever is rigid and hard. This is another paradox: what is soft
is strong." - Lao-Tzu

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message