title: Convert string to objectid mongodb
body: <p>I have a collection of 800 ish documents,  I would like to create a new one from this collection by adding a new field which is based on another field as follows:</p>
  
  <p>Basically my foo_collection documents contains a field that has been set as a string however I want to convert it to a new one by "casting" it's value to a mongoose Id: </p>
  
  <p>I tried this so far but I get the error : Invalid onjectId: Length</p>
  
  <pre><code>db.getCollection('foo_collection').aggregate([
  {
      "$addFields ":{
          "bar" :  ObjectId("$bar_id")
      }
  },
  {"$out":"new_foo_collection"}
  ])
  </code></pre>
  
  <p>the expected result is a new collection with documents that has 1 more field "bar" with the value an ObjectId()</p>
  
  <p>Thanks for your help !</p>