couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mclendon, William C III" <>
Subject Re: Querying a view with a complex key with a wildcard
Date Tue, 29 Mar 2011 19:17:49 GMT

On 3/29/11 12:43 PM, "Paul Davis" <> wrote:

>On Tue, Mar 29, 2011 at 2:39 PM, Mclendon, William C III
><> wrote:
>> Hi,
>> I've got a view that is built from a map.js that looks like this:
>> function(doc)
>> {
>>  if(doc['record type']=='search')
>>    {
>>    emit( [doc.status, doc.time], doc )
>>    }
>> }
>> Where the doc.status field is a string that is either "Running" or
>>"Finished" and doc.time is a floating point value from 0 and up
>>representing the time a task took to complete.
>> I'd like to be able to query the documents that are 'Finished' and sort
>>by time.  This query works:
>> ... /_view/searches_by_status?startkey=["Finished",0]&include_docs=true
>> But it doesn't sortŠ So if I change it to:
>How do you mean, doesn't sort? I assure you its sorted, but most
>likely just not sorted as you expect.

Well, yea... it's in ascending order be default since descending=false is
the default.  I'd like descending order so my keys would be in an ordering
something like this:

["Finished", 83.2]
["Finished", 77.3]
["Finished", 43.2]
["Finished", 0]

If I run the view in futon, I can change the ordering of the key field in
the table and see the right thing but I'd like to get this out of my view
query through the URI as well.

>> ... 
>> Then I only get values containing time=0
>> Why does adding the descending=true option change the results?
>> I've also tried this:
>> Š 
>> But this one doesn't return anything.
>> Is there a way to query this view to get records with a particular
>>value in the doc.status field and still sort the fields?
>This will return rows sorted by doc.time in ascending order.
>Will return docs sorted descending by doc.time.

Ah, this works! 

I'm sure it's obvious that I'm fairly new to couchdb... Where might I go
to look up what's happening with the {} values in the key?  I've picked
through the couchdb wiki a bit and have a couple couchdb books but haven't
run across an explanation of this info in my searches :(


>> Thanks in advance for any advice and/or help!
>>  -William

View raw message