title: Mongoose - How do you update a specific object inside an array of reference objects?
body: <p>I have this schema: </p>
  
  <pre><code>var UserSchema = new Schema({
    name: String,
    username: {
      type: String,
      required: [true, "Please enter a username"],
      minlength: [6, "Username must be at least 6 characters"],
      maxlength: [15, "Username cannot exceed 15 characters"],
      unique: true
    },
    password: {
      type: String,
      required: [true, "Please enter a password"],
      minlength: [6, "Password must be at least 6 characters"],
      maxlength: [17, "Password cannot exceed 17 characters"],
    },
    roommates: [{roomate: {type: Schema.Types.ObjectId, ref: "User"}, status: {type: String, default: "pending"}}]
  })
  </code></pre>
  
  <p>This is my controller (the id's are just two random Id's of users I have in my db, so ignore that: </p>
  
  <pre><code>update: function(req, res) {
      User.findOne({
        _id: "57f1645c05ec06099ead3db6", 'roommates._id': "57f16436190a09099a1ddbde"
      }, {'roommates.$': 1}, function(err, user1) {
        user1.update()
      })
    }
  }
  </code></pre>
  
  <p>My controller is totally useless right now. The objective is to reach inside that roommates array, find ONE specific object, and UPDATE just that one so it's status changes from 'Pending' (which is the default) to a new string value that I can set in the controller.</p>
  
  <p>I'm getting lost in the queries. How would you do this using mongoose? </p>
  
  <p>Thanks</p>