Nanodeath on couchdb irc solved this ->
function(d){
if(d.type != 'reply'){
emit(d.touid, d);
if(d.touid != d.fromuid){
if (d.replycount>0)
emit(d.fromuid, d);
}
}
}
Usage: In [7]: replies = [ (x.id, x.value) for x in
anondb.view('_view/truthbox/inbox',key=z.uid) ]
Schema:
class Anonmessage(Document):
subject = TextField()
read = BooleanField()
fromread = BooleanField()
toread = BooleanField()
msg = TextField()
background = TextField()
type = TextField()
reply = TextField()
fromuid = LongField()
replycount = IntegerField()
touid = LongField()
created = DateTimeField(default=datetime.datetime.now())
time =TimeField(default=datetime.datetime.now())
date = DateField(default=datetime.date.today())
On 1/6/09, paul jobs <[email protected]> wrote:
>
> querycode = 'function(d) { if ((d.touid == "%d" || d.fromuid=="%d") &&
> d.type!="reply" ) emit(d.created,d); }'%(uid, uid)
> anonmsgs = [ (x.id,x.value) for x in varnishanondb.query(querycode,
> descending=True) ]
>
> how to use this using slices -> when there are 2 variables in the query
> instead of just d.author
>
> On 12/28/08, Paul Davis <[email protected]> wrote:
>>
>> Behold the power of slices!
>>
>> function(doc)
>> {
>> if(doc.author) emit(doc.author, 1);
>> }
>>
>> All docs that have Tolkien as an author:
>>
>> http://127.0.0.1:5984/db_name/_view/design_doc/foo?key="Tolkien"
>>
>> Obviously, s/Tolkien/Rowling/ for books by Rowling.
>>
>> The more important part is this though, say you wanted all books with
>> authors alphabetically from Rowling to Tolkein:
>>
>> http://127.0.0.1:5984/db_name/_view/design_doc/foor?startkey=
>> "Rowling"&andkey="Tolkien"
>>
>> And remember, you can emit arbitrary JSON. There's a defined sort
>> order over the entire range of JSON. See the View collation wiki page.
>>
>> HTH,
>>
>> Paul Davis
>>
>>
>> On Sun, Dec 28, 2008 at 4:06 PM, Bernd Eickhoff <[email protected]> wrote:
>> > Hello,
>> >
>> > I am trying to get to grips with Couchdb. Though it looks very
>> interesting,
>> > I just dont understand how to query Couchdb for an abitrary value, as is
>> > possible with sql. Imagine I had a number of very simple documents,
>> like:
>> >
>> > {"_id":"b1","_rev":"3573740128", "book":"Potter","author":"Rowling"}
>> >
>> > and I wanted to find all books written by Mr Tolkien?
>> >
>> > I could create a view like:
>> >
>> > function(doc) { if (doc.author == "Tolkien") emit(null, doc); }
>> >
>> > and then query:
>> >
>> > http://127.0.0.1:5984/books/_view/byauthor/tolkien
>> >
>> > Is there any way to pass "Tolkien" as a variable to the view, or do I
>> have
>> > to create a new view, every time I want to query for another keyword?
>> >
>> > Thanks
>> >
>> > Bernd
>> >
>>
>
>