You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by "Panop S." <au...@gmail.com> on 2010/08/05 06:36:10 UTC
Which is the better way to query
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 ).
Would like to get suggestion on this is the correct way ? Is it
possible to make this by just one request with nickname request?
Bests,
Aun.
Re: Which is the better way to query
Posted by Jason Smith <jh...@couch.io>.
On Thu, Aug 5, 2010 at 11:36, Panop S. <au...@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