title: Custom sorting in MongoDB
body: <p>I am creating a NodeJS application and I want to sort contacts by last name. The problem is the name part must be saved as one string and when I use the sort function in MongoDB, the defaults are ascending or descending. Is it possible to create a custom sort? For example, if the information is </p>
  
  <pre><code>[
      {
          _id: "565c9f1ad5015e516ea99b91",
          name: "David Li"
      },
      {
          _id: "56642c73b35adedf4fad6c30",
          name: "George Chan"
      }
  ]
  </code></pre>
  
  <p>how can I sort it by the last name? </p>
  
  <p>Currently I am sorting like this:</p>
  
  <pre><code>var options = {
      sort: "name"
  };
  
  collection.find({}, options, function(err, cursor) {
      res.json(cursor);
  });
  </code></pre>