couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeremy Wall" <jw...@google.com>
Subject Re: Associating users and comments
Date Wed, 01 Oct 2008 02:29:10 GMT
Whoops hit the send key before I was ready...

Anyway with the combination of a Map and Reduce you should be able to do
exactly what you want.

On Tue, Sep 30, 2008 at 9:28 PM, Jeremy Wall <jwall@google.com> wrote:

> If user and document all have unique identifiers then just recording the
> identifier as linking metadata in the document should be enough. The user
> and document info can change but the id never does. The Autogenerated
> Document ID's that couchdb creates for you would be perfect.
>
> This is how do it for the CouchDB backed CMS I'm building.
>
> On Tue, Sep 30, 2008 at 9: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?
>
>
> With a reduce you can can take the map results and order/combine them in
> whatever data structure you want. Then using start_key and end_key with
> count you can page through the results.
>
> Say for instance:
>
> function(key, values) {
>  if( key[1] == 0 ) {
>
> }
>
>>
>>
>> Cheers,
>> Ben
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message