title: how to sort documents using the erlang map reduce in riak
body: <p>i'm using riak to store json documents right now, and i want to sort them based on some attribute, let's say there's a key, i.e</p>
  
  <p>{
       "someAttribute": "whatever",
       "order": 1
   }</p>
  
  <p>so i want to sort the documents based on the "order".  </p>
  
  <p>I am currently retrieving the documents in riak with the erlang interface.  i can retrieve the document back as a string, but i dont' really know what to do after that. i'm thinking the map function just reduces the json document itself, and in the reduce function, i'd make a check to see whether the item i'm looking at has a higher "order" than the head of the rest of the list, and if so append to beginning, and then return a lists:reverse.</p>
  
  <p>despite my ideas above i've had zero results after almost an entire day, i'm so confused with the erlang interface in riak.  can someone provide insight on how to write this map/reduce function, or just how to parse the json document?</p>