title: Mongoose schema, set key variable
body: <p>I'm using expressjs, mongodb and mongoose, I'm trying to update the counts object of the following schema:</p>
  
  <pre><code>var UsersSchema = new Schema({
    username: { type: String, required: true },
    counts: {
      followers: { type: Number, default: 0 },
      trips: { type: Number, default: 0 },
      videos: { type: Number, default: 0 }
    }
  })
  </code></pre>
  
  <p>And the update part (not working):</p>
  
  <pre><code>var key = 'trips' // set dynamically, could be 'videos' or 'followers'
  Users.update({'username': username}, {$set: {'counts.key': 12}}, callback)
  </code></pre>
  
  <p>Working example but not dynamic:</p>
  
  <pre><code>Users.update({'username': username}, {$set: {'counts.trips': 12}}, callback)
  </code></pre>
  
  <p>Any ideas ?</p>