incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul Davis" <paul.joseph.da...@gmail.com>
Subject Re: Associating users and comments
Date Wed, 01 Oct 2008 02:26:22 GMT
1. To prevent the need to re-update all your sub-records, use a
uniquely identifying piece of data that doesn't change. Ie, use the
user docid instead of slug. This prevents you from being able to
display a post without fetching the user doc, but getting the whole
shebang in one get should alleviate that. (as was the original
intent).

2. You're right that you the view count only gives you that many rows,
regardless of what type. For the first "Give me back 5 customers with
their orders" I'd do a reduce with group_level=1 and sum the rows,
then a second get to get that many rows from the view. The second
question about getting the latest 5 orders for each customer would
require a different view probably. I have the feeling it should be
doable with a clever emit, but I'm a bit tired so its not
materializing.

Paul

On Tue, Sep 30, 2008 at 10:10 PM, Ben Bangert <ben@groovie.org> wrote:
> I have a setup similar to what Chris Lenz documented with comments and posts
> that they go to. However, since user data changes, I'd like to figure out a
> way to get back the user record either before or after the comment they made
> rather than having the relevant user data inside every comment posted (which
> would require a ton of updates should the user info change).
>
> So given a database with types of post, comment, user, how would I get back
> a few posts, with their comments, and with the comment posters full name
> (which is in a separate document)?
>
> Also, with regards to the originally documented trick to return both custom
> and order documents:
>
> function(doc) {
>  if (doc.Type == "customer") {
>    emit([doc._id, 0], doc);
>  } else if (doc.Type == "order") {
>    emit([doc.customer_id, 1], doc);
>  }
> }
>
> From my understanding, imposing a count limit on this doesn't discriminate
> between customers or orders, just total rows returned from the view. So how
> would I say, give me back 5 customers with their orders? Or even, give me
> back 10 customers with their last 5 orders?
>
> Cheers,
> Ben

Mime
View raw message