title: Mongodb Join on _id field from String to ObjectId
body: <p>I have two collections</p>
  
  <ol>
  <li><p>User</p>
  
  <pre><code>{
     "_id" : ObjectId("584aac38686860d502929b8b"),
     "name" : "John"
  }
  </code></pre></li>
  <li><p>Role</p>
  
  <pre><code>{
     "_id" : ObjectId("584aaca6686860d502929b8d"),
     "role" : "Admin",
     "userId" : "584aac38686860d502929b8b"  
  }
  </code></pre></li>
  </ol>
  
  <p>I want to join these collection based on the <strong>userId</strong> (in <strong>role</strong> collection) - <strong>_id</strong> ( in <strong>user</strong> collection).</p>
  
  <p>I tried the below query:</p>
  
  <pre><code>db.role.aggregate({
    "$lookup": {
      "from": "user",
      "localField": "userId",
      "foreignField": "_id",
      "as": "output"
    }
  })
  </code></pre>
  
  <p>This gives me expected results as long as i store userId as a ObjectId. When my userId is a string there are no results. 
  Ps: I tried </p>
  
  <blockquote>
    <p>foreignField: '_id'.valueOf()</p>
  </blockquote>
  
  <p>and </p>
  
  <blockquote>
    <p>foreignField: '_id'.toString()</p>
  </blockquote>
  
  <p>. But no luck to match/join based on a ObjectId-string fields.</p>
  
  <p>Any help will be appreciated.</p>