title: Reference another Schema in Mongoose
body: <p>so I have to Schemas. PostSchema and UserSchema</p>
  <pre><code>const mongoose = require(&quot;mongoose&quot;)
  
  const PostSchema = new mongoose.Schema({
      content: {
          type: String,
          required: true,
      },
      likes: {
          type: Number,
          required: true
      },
      rescreams: {
          type: Number,
          required: true
      },
      user: {
          type: mongoose.Schema.Types.ObjectId,
          ref: 'User'
      },
      createdAt: {
          type: Date,
          default: Date.now
      }
  })
  
  module.exports = mongoose.model(&quot;Post&quot;, PostSchema)
  </code></pre>
  <p>UserSchema:</p>
  <pre><code>const bcrypt = require(&quot;bcrypt&quot;);
  const mongoose = require(&quot;mongoose&quot;);
  
  const UserSchema = new mongoose.Schema({
    userName: { type: String, unique: true },
    email: { type: String, unique: true },
    password: String,
  });
  
  // Password hash middleware.
  
  UserSchema.pre(&quot;save&quot;, function save(next) {
    const user = this;
    if (!user.isModified(&quot;password&quot;)) {
      return next();
    }
    bcrypt.genSalt(10, (err, salt) =&gt; {
      if (err) {
        return next(err);
      }
      bcrypt.hash(user.password, salt, (err, hash) =&gt; {
        if (err) {
          return next(err);
        }
        user.password = hash;
        next();
      });
    });
  });
  
  // Helper method for validating user's password.
  
  UserSchema.methods.comparePassword = function comparePassword(
    candidatePassword,
    cb
  ) {
    bcrypt.compare(candidatePassword, this.password, (err, isMatch) =&gt; {
      cb(err, isMatch);
    });
  };
  
  module.exports = mongoose.model(&quot;User&quot;, UserSchema);
  </code></pre>
  <p>My question is: I'm trying to reference the User Object ID in the Post Schema. As you can see, I've done that with type: mongoose.Schema.Types.ObjectID. And I've seen this multiple times. But in my database, the User never shows up in the Document. What do I need to do?</p>
  <p>Cheers</p>