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: Querying a view with a complex key with a wildcard
Date Tue, 29 Mar 2011 18:43:02 GMT
On Tue, Mar 29, 2011 at 2:39 PM, Mclendon, William C III
<wcmclen@sandia.gov> 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.

> ... /_view/searches_by_status?startkey=["Finished",0]&include_docs=true&descending=true
>
> Then I only get values containing time=0
>
> Why does adding the descending=true option change the results?
>
> I've also tried this:
>
> … /_view/searches_by_status?startkey=["Finished",0]&endkey=["Finished",9999.9999]&include_docs=true&descending=true
>
> 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?
>

/_view/searches_by_status?startkey=["Finished"]&endkey=["Finished",{}]&include_docs=true

This will return rows sorted by doc.time in ascending order.

/_view/searches_by_status?startkey=["Finished",{}]&endkey=["Finished"]&include_docs=true&descending=true

Will return docs sorted descending by doc.time.

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

Mime
View raw message