couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sean Coates <s...@seancoates.com>
Subject View/join help
Date Sat, 27 Nov 2010 03:46:14 GMT
Hello.

I am (again) having trouble figuring out a view. Hopefully one of you smart people can help
(or at least someone can definitively tell me what I'm trying to do is impossible, and I'll
have to look into alternatives... I heard MySQL is on the uptake (-: ).

Background information:
I've set up an example database here: http://scoates-test.couchone.com/_utils/database.html?follow
/ http://scoates-test.couchone.com/follow

I have two types of documents. type=user and type=asset.
Example user: http://scoates-test.couchone.com/_utils/document.html?follow/c988a29740241c7d20fc7974be05f67d
Example asset: http://scoates-test.couchone.com/_utils/document.html?follow/c988a29740241c7d20fc7974be061d62
Users can follow other users (the type=user document's "following" field). The above example
user (username=bob) is "following" 2 users: 
"following": [
       "c988a29740241c7d20fc7974be05ec54", // username=aaron
       "c988a29740241c7d20fc7974be060bb4" // username=dale
   ]
 Assets are owned by a specific user. The above example asset is owned by c988a29740241c7d20fc7974be061d62
(username=bob).

Hopefully that makes sense.

I'd like to request assets that belong to users that bob is following (aaron and dale), and
I can't put my finger on view code that will allow this. I can easily emit all assets that
belong to c988a29740241c7d20fc7974be05f67d.

I *could* do it in two requests. First, I'd ask CouchDB for c988a29740241c7d20fc7974be05f67d,
and then POST the following as "keys" to a view that returns assets belonging to those keys,
but you'll note that my type=asset documents also have a "when" field, and I want to be able
to order by that by emitting [doc.owner, doc.when] as the key, and then using startKey/endKey.
So POST of keys is out, I think.

I *could* just join on the application side (query the following keys, make one request for
each of these keys, then sort on the app side), but this breaks pagination really badly (I'd
need to request a limit of pageSize for each following), and that gets out of control very
quickly (if a user is following 1000 users, that's 10,000 records per page).

Neither of these solutions works for me. I'd like to do it *in* CouchDB.

I'm truly stumped. Please help.

S
Mime
View raw message