title: Mongoose findOneAndUpdate: update an object in an array of objects
body: <p>I have the exact same issue as described in this thread (hence the similar title): <a href="https://stackoverflow.com/questions/43128561/mongoose-findoneandupdate-updating-an-object-inside-an-array-of-objects">Mongoose findOneAndUpdate -- updating an object inside an array of objects</a></p>
  
  <p>Given this model:</p>
  
  <pre><code>const SavedFoodsSchema = new Schema({
    user: { type: Schema.Types.ObjectId, ref: 'User' },
    list: [
      {
        id: { type: Number, required: true, unique: true },
        name: { type: String, required: true },
        points: { type: Number, required: true }
      }
    ]
  })
  </code></pre>
  
  <p>I wrote the following function just to test finding a document in the SavedFoods Collection based on the userId param, and then in the <code>list</code> array, for the first object in the array, setting the <code>name</code> to "Something else".</p>
  
  <pre><code>function updateFood (userId) {
    // This didn't work
    SavedFoods.findOneAndUpdate(
      {
        id: userId,
        'list.id': 0
      },
      {
        $set: {
          'list.$.name': 'Something else'
        }
      },
      null,
      (err) =&gt; {
        if (err) {
          console.log('Error:', err)
        } else {
          console.log('Updated', userId)
        }
        process.exit(0)
      }
    )
  }
  </code></pre>
  
  <p>The callback is called and there is no error, however the the changes do not get reflected in my db.</p>
  
  <p>Am I doing something wrong?</p>