title: Confused about Types.ObjectId and Schema.Types.ObjectId from Mongoose
body: <p>I'm trying to created nested schema with mongoose, attaching a user_id field for subdocuments. I found out this approach</p>
  <pre class="lang-js prettyprint-override"><code>const {Schema} = require(&quot;mongoose&quot;);
  var user_id = {
      type:Schema.Types.ObjectId,
      ref:&quot;User&quot;,
    },
  </code></pre>
  <p>but later i found that <code>Types</code> can be imported from mongoose on top level , but the definition of the ObjectId is very different from <code>Schema.Types</code>, as such</p>
  <pre class="lang-js prettyprint-override"><code>const {Types} = require(&quot;mongoose&quot;);
  var user_id = {
      type:new Types.ObjectId(),
      ref:&quot;User&quot;,
    },
  </code></pre>
  <p>I couldn't find documentation on this nuance....I guess i should use a consistent approach across the app, so can someone help to explain?</p>
  <p>*Edit: I think the one I should use should be consistent with the way _id is defined for the <code>User</code> table, but which one was it used?</p>