title: Finding MongoDB documents by _id failing on the type of ObjectId
body: <p>I'm struggling to find MongoDB documents by their <code>_id</code> field in my ReactJS project.</p>
  <p>My collection has documents that looks like so (for example):</p>
  <pre><code>    _id: ObjectId(&quot;5f6651112efc19f33b34fc39&quot;)
      title: &quot;This is a title&quot;
      status: true
  </code></pre>
  <p>I'm using this (greatly simplified) code in a function to find the documents that match the <code>id</code> passed in:</p>
  <pre><code>const id = '5f6651112efc19f33b34fc39';
  await mongoCollection.find({_id:ObjectId(id)});
  </code></pre>
  <p><code>ObjectId</code> is defined like so:</p>
  <pre><code>const ObjectId = require('mongodb').ObjectID;
  </code></pre>
  <p>Yet even if I hard coded the <code>id</code> variable to be the ObjectId string from the document in my database, it fails with this error:</p>
  <p><code>Uncaught (in promise) Error: invalid ObjectId, ObjectId.id must be either a string or a Buffer, but is [{&quot;type&quot;:&quot;Buffer&quot;,&quot;data&quot;:[]}]</code></p>
  <p>Printing out <code>id</code> and <code>ObjectId(id)</code> before the <code>await</code> line results in the following:</p>
  <p><a href="https://i.stack.imgur.com/6vsXq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6vsXq.png" alt="Console.log screenshot" /></a></p>
  <p>How should I be satisfying this warning?</p>
  <p>Edit: I'm defining my app/collection like so:</p>
  <pre><code>const app = new Realm.App({ id: &quot;&lt;app-id&gt;&quot;, timeout: 10000 });
  const mongo = app.services.mongodb('mongodb-atlas');
  const mongoCol = mongo.db('&lt;databaseName&gt;').collection('&lt;collectionName&gt;');
  </code></pre>