incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Metson <>
Subject Re: Design question, article with logs of comments and ratings
Date Fri, 25 Feb 2011 13:25:44 GMT
	Let's say you have a +1 or -1 vote for a given document. You could record this with a document

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


	"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 ( emit(doc.article,;

And query it for a specific article with


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


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

View raw message