title: Is it possible to convert a hex string to mongodb object Id during aggregation query?
body: <p>I want to convert a hex string to mongodb ObjectId before project that field.</p>
  
  <p>I have tried this:</p>
  
  <p>Data in products document : </p>
  
  <p><code>{
      _id : ObjectId("571b73c2b190ecdc598b4567")
      categories : [
          "571b73c2b190evdc598bad67",
          "571b73c2b1c0evdc598cad67"
      ]
  }</code></p>
  
  <pre class="lang-js prettyprint-override"><code>  db.products.aggregate([
      { $match : { _id : ObjectId("571b73c2b190ecdc598b4567") } },
      { $unwind : '$categories' },    
      { $project : { 'category_id' : ObjectId("$categories") } },
      { $lookup : { from : 'categories', localField: 'categories', foreignField : '_id', as : 'categoriesData' } }
  ]).pretty()
  </code></pre>
  
  <p>But it returns an error:</p>
  
  <blockquote>
    <p>Error: invalid object id: length</p>
  </blockquote>