You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by He Shiming <he...@gmail.com> on 2011/02/25 04:51:13 UTC

Design question, article with logs of comments and ratings

Hi,

I've got a design question. The scenario is: the database stores a
series of articles, and each article can be commented and rated.

For articles, naturally I'll have {"_id": "article-id", "type":
"article" ...} . And each article is a single document in the
database.

I'm not sure what form should I use to put ratings and comments. I
would like to keep a history of rating and comments for each article,
but still be able to calculate average rating easily. I may also need
"likes" and "dislikes" for each of the comment. So it'll be sorted in
a custom order.

How do I design documents to store such information? Thanks!

-- 
Best regards,
He Shiming

Re: Design question, article with logs of comments and ratings

Posted by Simon Metson <si...@googlemail.com>.
Also the "Joins Redux" on http://blog.couchone.com/post/446015664/whats-new-in-apache-couchdb-0-11-part-two-views is handy, probably does what you want for comments...

Sent with Sparrow 
On Saturday, 26 February 2011 at 04:32, Aravinda VK wrote:
This might help.
> http://www.cmlenz.net/archives/2007/10/couchdb-joins
> 
> On Sat, Feb 26, 2011 at 7:46 AM, He Shiming <he...@gmail.com> wrote:
> 
> > On Fri, Feb 25, 2011 at 9:25 PM, Simon Metson
> > <si...@googlemail.com> wrote:
> > > And query it for a specific article with
> > http://localhost:5984/voting/_design/vote/_view/vote?group=true&key=%22foo%22
> > > 
> > > Mike Miller did a nice summary of how you could do time binned data for
> > your historical info (using the timestamp field in the vote doc) on
> > http://nosqltapes.com/video/understanding-mapreduce-with-mike-miller
> > > 
> > > HTH
> > > Cheers
> > > Simon
> > 
> > So each comment and rating is a single document. And grouping should
> > be used to reduce. Thank you very much Simon. I got the idea now.
> > 
> > --
> > Best regards,
> > He Shiming
> 
> 
> 
> -- 
> Regards
> Aravinda | ಅರವಿಂದ
> http://aravindavk.in
> 

Re: Design question, article with logs of comments and ratings

Posted by Aravinda VK <ha...@gmail.com>.
This might help.
http://www.cmlenz.net/archives/2007/10/couchdb-joins

On Sat, Feb 26, 2011 at 7:46 AM, He Shiming <he...@gmail.com> wrote:

> On Fri, Feb 25, 2011 at 9:25 PM, Simon Metson
> <si...@googlemail.com> wrote:
> > And query it for a specific article with
> >
> >
> http://localhost:5984/voting/_design/vote/_view/vote?group=true&key=%22foo%22
> >
> > Mike Miller did a nice summary of how you could do time binned data for
> your historical info (using the timestamp field in the vote doc) on
> http://nosqltapes.com/video/understanding-mapreduce-with-mike-miller
> >
> > HTH
> > Cheers
> > Simon
>
> So each comment and rating is a single document. And grouping should
> be used to reduce. Thank you very much Simon. I got the idea now.
>
> --
> Best regards,
> He Shiming
>



-- 
Regards
Aravinda | ಅರವಿಂದ
http://aravindavk.in

Re: Design question, article with logs of comments and ratings

Posted by He Shiming <he...@gmail.com>.
On Fri, Feb 25, 2011 at 9:25 PM, Simon Metson
<si...@googlemail.com> wrote:
> And query it for a specific article with
>
> http://localhost:5984/voting/_design/vote/_view/vote?group=true&key=%22foo%22
>
> Mike Miller did a nice summary of how you could do time binned data for your historical info (using the timestamp field in the vote doc) on http://nosqltapes.com/video/understanding-mapreduce-with-mike-miller
>
> HTH
> Cheers
> Simon

So each comment and rating is a single document. And grouping should
be used to reduce. Thank you very much Simon. I got the idea now.

-- 
Best regards,
He Shiming

Re: Design question, article with logs of comments and ratings

Posted by Simon Metson <si...@googlemail.com>.
Hi,
	Let's say you have a +1 or -1 vote for a given document. You could record this with a document like:

{
	"article" : "article-id", "vote": 1, "timestamp": now()
}

or 

{
	"article" : "article-id", "vote": -1, "timestamp": now()
}

(where now() is some function you run client side to get the time.

You'd then be able to get the rating via a simple map function and a _sum reduce:

function(doc) {
  if (doc.vote) emit(doc.article, doc.vote);
}

And query it for a specific article with

http://localhost:5984/voting/_design/vote/_view/vote?group=true&key=%22foo%22

Mike Miller did a nice summary of how you could do time binned data for your historical info (using the timestamp field in the vote doc) on http://nosqltapes.com/video/understanding-mapreduce-with-mike-miller

HTH
Cheers
Simon

On 25 Feb 2011, at 03:51, He Shiming wrote:

> Hi,
> 
> I've got a design question. The scenario is: the database stores a
> series of articles, and each article can be commented and rated.
> 
> For articles, naturally I'll have {"_id": "article-id", "type":
> "article" ...} . And each article is a single document in the
> database.
> 
> I'm not sure what form should I use to put ratings and comments. I
> would like to keep a history of rating and comments for each article,
> but still be able to calculate average rating easily. I may also need
> "likes" and "dislikes" for each of the comment. So it'll be sorted in
> a custom order.
> 
> How do I design documents to store such information? Thanks!
> 
> -- 
> Best regards,
> He Shiming