couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Stockton <>
Subject Key sorting by integer
Date Fri, 12 Mar 2010 00:16:06 GMT

I am working on the sorting feature of our application, currently
string sorting is working well, but would like to sort by date and
integer value as opposed to following the collation rules defined at
[1]. I have a view function as defined below:

  function(doc) {
    if(doc.type && 'model' == doc.type && doc.model && {
      for(key in {
        emit([doc.model, key,[key]], doc._id); }}}

Which index's documents of the following properties:
     "_id": "ffeff3a1ba7c20c9a348074387c9f091",
     "data": {
         "Rental_id": "12271",
         "Rental Date": "8/18/2005 4:33",
         "DVD_id": "3866",
         "Name": "DEAN SAUER",
         "Return Date": "8/20/2005 23:10"
     "type": "model",
     "model": "Rental"

I sort using a call like so:

This returns a result such as:
  9992, 9991, 9990, 999, 9989, 9988

This is expected according to the collation rules and string sorting.
However we would like to achieve the sorting our users expect for
integer column types, such as:
  9992, 9991, 9990, 9989, 9988, 999

Our immediate thought for a solution for this was to add zero
left-padding to our integer columns; which would however be a
significant UI and back end change that we would like to avoid if

Thank you for your time,


[1] View_Collation -

View raw message