title: What is an equivalent of Mongodb .sort with several parameters in mongoosejs?
body: <p>Suppose I have collection foo:</p>
  
  <pre><code>&gt; db.foo.find()
  { "_id" : ObjectId("5076865a72da558dd40c819d"), "a" : 1, "b" : 5 }
  { "_id" : ObjectId("5076866f5c70b3b37c048494"), "a" : 2, "b" : 4 }
  { "_id" : ObjectId("5076866f5c70b3b37c048495"), "a" : 3, "b" : 6 }
  { "_id" : ObjectId("507686835c70b3b37c048496"), "a" : 0, "b" : 4 }
  </code></pre>
  
  <p>I want to sort it by <code>b</code>, then by <code>a</code>:</p>
  
  <pre><code>&gt; db.foo.find().sort({b:-1,a:-1})
  { "_id" : ObjectId("5076866f5c70b3b37c048495"), "a" : 3, "b" : 6 }
  { "_id" : ObjectId("5076865a72da558dd40c819d"), "a" : 1, "b" : 5 }
  { "_id" : ObjectId("5076866f5c70b3b37c048494"), "a" : 2, "b" : 4 }
  { "_id" : ObjectId("507686835c70b3b37c048496"), "a" : 0, "b" : 4 }
  </code></pre>
  
  <p>Apparently, hash passed to sort() preserves the order of keys:</p>
  
  <pre><code>&gt; db.foo.find().sort({a:-1,b:-1})
  { "_id" : ObjectId("5076866f5c70b3b37c048495"), "a" : 3, "b" : 6 }
  { "_id" : ObjectId("5076866f5c70b3b37c048494"), "a" : 2, "b" : 4 }
  { "_id" : ObjectId("5076865a72da558dd40c819d"), "a" : 1, "b" : 5 }
  { "_id" : ObjectId("507686835c70b3b37c048496"), "a" : 0, "b" : 4 }
  </code></pre>
  
  <p>What I need is to duplicate this behavior in Node.js application that uses mongoosejs as DB wrapper. I know that with one sorting parameter I can go with</p>
  
  <pre><code>Foo.find({},[],{sort:{b:-1}}, callback)
  </code></pre>
  
  <p>Having two parameters confuses me as both <code>Foo.find({},[],{sort:{b:-1, a:-1}}, callback)</code> and <code>Foo.find({},[],{sort:{a:-1, b:-1}}, callback)</code> return the elements in the same order (sorted by <code>a</code>) - as it should, as obviously hashes/objects have no key order.</p>
  
  <p>I know that you can pass arrays(e.g. <code>['b','a']</code>), but am still unsure how to set reverse order: <code>['-b','-a']</code>, although being recoginzed by mongoosejs, sorts in direct order.</p>