couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Smith <...@couch.io>
Subject Re: Which is the better way to query
Date Thu, 05 Aug 2010 07:58:51 GMT
On Thu, Aug 5, 2010 at 11:36, Panop S. <aun.panop@gmail.com> wrote:

> Hi,
>
>         My system have document like this
>
>              id = 1
>              nickname = A
>
>
>              id = 2
>              parent id = 1
>
>
>             id = 3
>             parent  id = 1
>
>
>            id = 4
>            parent  id = 1
>
>
>           Now I use map function to emit  ( nickname, doc) so the request
> come from the key of nickname and
> I make another request to get all child which has (id = parent id ).
>

I think with those documents it is not possible. You have a few choices.

1. Make multiple requests like you are doing now
2. If you know the nickname when you *store* document 2, 3, 4, etc. then add
the nickname to that document too. For document 1, you would emit([nickname,
false], doc) and the others would emit([nickname, true]). Query for
startkey=[nickname] endkey=[nickname, {}]. You will get all documents about
nickname. Since "false" comes before "true" in a sort, the parent document
will always be first, and the other documents will be next.

-- 
Jason Smith
Couchio Hosting

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