title: How do i $set and $push in one update MongoDB?
body: <p>I'm trying to <code>$push</code> and <code>$set</code> at the same time, <code>$push</code> is working just fine, when it comes to <code>$set</code>, it generates this error:</p>
  
  <blockquote>
    <p>MongoError: The positional operator did not find the match needed from
    the query. Unexpanded update: files.$.name</p>
  </blockquote>
  
  <p>Here's the code</p>
  
  <pre><code>Course.update(
      {
          _id: req.body.courseId,
          'files.fileUrl': { $ne: url }
      },{
          $push: { files: { fileUrl: url } },
          $set: {'files.$.name': file.name},
      }, function(err, count) {
          if (err) return next(err);
          console.log("Successfully saved")
      });
  </code></pre>
  
  <p>and the ORM model, I'm using mongoose</p>
  
  <pre><code>var CourseSchema = new Schema({
      files: [{
          fileUrl: String,
          name: { type: String, default: 'File name'}
      }]
  });
  </code></pre>
  
  <p>Any help would be appreciated. Thanks.</p>