title: Mongoose DB watch specific attribute change
body: <p>In a Mean stack app that am exploring, came across an issue where there is a need to sort stored documents by the length of an array attribute.</p>
  
  <pre><code>var UserSchema = new Schema({
      name: String,
      email: {
          type: String,
          lowercase: true
      },
      role: {
          type: String,
          default: 'user'
      },
      password: String,
      provider: String,
      salt: String,
      facebook: {},
      photos:[String],
      photoCount: Number,
      plants:[{type: mongoose.Schema.Types.ObjectId, ref : 'Plant'}],
      imgurAlbumID: String,
      createdAt : {type:Date, default: new Date()}
  
  });
  </code></pre>
  
  <p>I will like to bring your attention to <b>photos</b> array and <b>photoCount</b>.</p>
  
  <p>Want to implement a pre save hook for solely 1 attribute, in this case <b>photos</b>.</p>
  
  <p>However, from what I know, the only solution I can think of is adding a pre save hook that watches all other attributes as well. Am trying to only watch for 1 single attribute to update the <b>photoCount</b> which stores a simple Integer value for the length count of the <b>photos</b> array. </p>
  
  <p>Does anyone know of a resource that I should be reading up on?</p>