title: How to have an auto calculated attribute in mongoose schema
body: <p>suppose I have following mongoose schema in Node.js</p>
  
  <pre><code>var schema = new mongoose.Schema({
      views:Number,
      clicks:Number,
      ctr:Number
  })
  </code></pre>
  
  <p>In which I want that CTR attribute should be automatically calculated by a formula based on values of other attributes, i.e lets say</p>
  
  <blockquote>
    <p><strong>ctr = clicks / views</strong></p>
  </blockquote>
  
  <p>I don't want to have CTR as a virtual field because based on the value of CTR I will sort all documents of my collection and apparently sorting is not possible based on virtual fields. So I was wondering if there is any way to have calculated attributes in mongoose schema which gets automatically updated on update of any of the dependent attribute/field</p>