Search code examples
jqueryjsoncouchdbcouchdb-futonnosql

couchDB sort result array by date if date is stored in an array of integers?


I'm storing couchDB docs and they have an attribute date which I want to sort by.

{

  ...blahblah...

  "date": [
    2015,
    5,
    16
  ]
}

I can't seem to figure out how to make a view that allows me to supply a startdate=[2015,5,1]&enddate=[2015,5,31] query. I want to get the stuff for May (month 5)


Solution

  • It should be as simple as:

    function (doc) {
      emit(doc.date);
    }
    

    Then your query needs to be: start_key=[2015,5,1]&end_key=[2015,5,31]

    Check out the documentation