title: Mongoose Populate, Do I have to keep schemas in the same file?
body: <p>I am trying to populate by using Mongoose. This is what it looks like so far:</p>
  <p>schema.ts</p>
  <pre><code>const UserSchema = new mongoose.Schema({
    id: String,
    name: String,
  });
  const UserModel = mongoose.model(&quot;User&quot;, UserSchema, &quot;users&quot;);
  
  const ShiftSchema = new mongoose.Schema({
    userId: {
      type: String,
      required: true,
    },
    date: {
      type: String,
      required: true,
    },
    startTime: String,
    endTime: String,
  });
  
  ShiftSchema.virtual(&quot;user&quot;, {
    ref: &quot;User&quot;,
    localField: &quot;userId&quot;,
    foreignField: &quot;id&quot;,
    justOne: true,
  });
  
  const ShiftModel = mongoose.model(&quot;Shift&quot;, ShiftSchema, &quot;shifts&quot;);
  
  export default ShiftModel;
  </code></pre>
  <p>shift.ts</p>
  <pre><code>const shifts = await ShiftModel.find({}).populate(&quot;user&quot;);
  </code></pre>
  <p>So this code is working fine, it is working as expects and populating user data into shift data.</p>
  <p>What I'm currently having trouble with is organizing this. I need to separate schemas into separate files however if I try to separate the userSchema and UserModel into a different file, populate doesn't work anymore. Any ideas on a workaround for this?</p>
  <p>Also, by the way, I am using a custom ID and not the default ID supplied by MongoDB.</p>
  <p>What I've tried:</p>
  <pre class="lang-js prettyprint-override"><code>import mongoose from &quot;mongoose&quot;;
  
  export const UserSchema = new mongoose.Schema({
    id: String,
    name: String,
  });
  export const UserModel = mongoose.model(&quot;User&quot;, UserSchema, &quot;users&quot;);
  </code></pre>
  <p>When I try to run my script, I get an error saying that Schema hasn't been registered for model &quot;User&quot;.</p>