You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by tu <tu...@gmail.com> on 2010/11/05 10:22:37 UTC

want to get json result from more than one document

I want to implement a blog server. I design two type of documents: "Author"
and "Blog". A "Blog" document contains a field "author_uid" to refer a
"Author" document.

I use CouchApp framework to show list of  recent posts. I find I have to
invoke couchdb server many times to show both blog body and author details
in each item.

Is their and solution to return a complete json result contains full
"Author" json object in "Blog" json object on server side?

Re: want to get json result from more than one document

Posted by Nils Breunese <N....@vpro.nl>.
tu wrote:

> I want to implement a blog server. I design two type of documents: "Author"
> and "Blog". A "Blog" document contains a field "author_uid" to refer a
> "Author" document.

That does sound like a pretty 'relational' approach to me. It's not that you can't do this, but you might want to consider blog posts to be a self contained document, since it makes some things more relaxing (updating an author's name would be less relaxing, but how often does that happen?). Doing away with 'joins' can really be a relief!

Nils.
------------------------------------------------------------------------
 VPRO
 phone:  +31(0)356712911
 e-mail: info@vpro.nl
 web:    www.vpro.nl
------------------------------------------------------------------------

Re: want to get json result from more than one document

Posted by Simon Metson <si...@googlemail.com>.
Hi,
	You could use the new-ish (added in 0.11) view joins, described  
nicely in http://blog.couchone.com/post/446015664/whats-new-in-apache-couchdb-0-11-part-two-views

A view like:

function(doc) {
   if (doc.type == "blog"){
     emit(doc._id, {post: doc.body, _id:doc.author});
   }
}

is probably want you want, queried by http://127.0.0.1:5984/test/_design/blog/_view/posts?include_docs=true

Cheers
Simon

On 5 Nov 2010, at 09:22, tu wrote:

> I want to implement a blog server. I design two type of documents:  
> "Author"
> and "Blog". A "Blog" document contains a field "author_uid" to refer a
> "Author" document.
>
> I use CouchApp framework to show list of  recent posts. I find I  
> have to
> invoke couchdb server many times to show both blog body and author  
> details
> in each item.
>
> Is their and solution to return a complete json result contains full
> "Author" json object in "Blog" json object on server side?