title: Getting BSON type of document field stored in MongoDB at mongo shell
body: <p>I have two documents in my MongoDB database. They are (simplified):</p>
  <pre><code>{
      &quot;_id&quot; : &quot;ONE&quot;,
      &quot;items&quot;: [
          42,
          0
      ]
  }
  
  {
      &quot;_id&quot; : &quot;TWO&quot;,
      &quot;items&quot;: [
          0,
          0
      ]
  }
  </code></pre>
  <p>They have been created by a client application (i.e. not using MongoDB shell) on which behavior I suspect (I mean, the application could have a bug and I'm trying to debug it).</p>
  <p>I suspect that document <code>ONE</code> has the numbers in <code>items</code> encoded as 32-bits integer at BSON level (i.e. <a href="https://docs.mongodb.com/manual/reference/bson-types/" rel="nofollow noreferrer">BSON type</a> 16) while in document <code>TWO</code> they are encoded in double (i.e. <a href="https://docs.mongodb.com/manual/reference/bson-types/" rel="nofollow noreferrer">BSON type</a> 1)</p>
  <p>I have tried to check it using usual <code>typeof</code> operator in JavaScript in the MongoDB shell but it seems they don't detect any difference:</p>
  <pre><code>&gt; typeof db.entities.find({_id: &quot;ONE&quot;})[0].items[0]
  number
  &gt; typeof db.entities.find({_id: &quot;ONE&quot;})[0].items[1]
  number
  &gt; typeof db.entities.find({_id: &quot;TWO&quot;})[0].items[0]
  number
  &gt; typeof db.entities.find({_id: &quot;TWO&quot;})[0].items[1]
  number
  </code></pre>
  <p>Is there any precise way of knowing the BSON type of a given piece of the MongoDB documents from MongoDB shell?</p>
  <p>Thanks in advance!</p>