hi, You can have a look at the section "View \ *Reversed result*" from the couchdb guide to understand why it did not work with your start key and descending order: http://guide.couchdb.org/editions/1/en/views.html
Good luck, mehdi On Tue, Mar 29, 2011 at 9:17 PM, Mclendon, William C III <[email protected] > wrote: > > > On 3/29/11 12:43 PM, "Paul Davis" <[email protected]> wrote: > > >On Tue, Mar 29, 2011 at 2:39 PM, Mclendon, William C III > ><[email protected]> 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. > > > >> ... > >>/_view/searches_by_status?startkey=["Finished",0]&include_docs=true&desce > >>nding=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",{}]&inc > >lude_docs=true > > > >This will return rows sorted by doc.time in ascending order. > > > >/_view/searches_by_status?startkey=["Finished",{}]&endkey=["Finished"]&inc > >lude_docs=true&descending=true > > > >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! > > > >> Thanks in advance for any advice and/or help! > >> -William > >> > > >
