title: Pull and addtoset at the same time with mongo
body: <p>I have a collection which elements can be simplified to this:</p>
  
  <p><code>{tags : [1, 5, 8]}</code></p>
  
  <p>where there would be at least one element in array and all of them should be different. I want to substitute one tag for another and I thought that there would not be a problem. So I came up with the following query:</p>
  
  <pre><code>db.colll.update({
    tags : 1
  },{
    $pull: { tags: 1 },
    $addToSet: { tags: 2 }
  }, {
    multi: true
  })
  </code></pre>
  
  <p>Cool, so it will find all elements which has a tag that I do not need (1), remove it and add another (2) if it is not there already. The problem is that I get an error: </p>
  
  <blockquote>
    <p>"Cannot update 'tags' and 'tags' at the same time"</p>
  </blockquote>
  
  <p>Which basically means that I can not do pull and addtoset at the same time. Is there any other way I can do this? </p>
  
  <p>Of course I can memorize all the IDs of the elements and then remove tag and add in separate queries, but this does not sound nice.</p>