In my case I couldn't use populate option without registering UserRole schema.
Role Schema
import mongoose from "mongoose";
const { Schema } = mongoose;
export interface IRole{
role:string;
}
const userRoleSchema = new Schema({
role: String,
});
// compile our model
const UserRole = mongoose.model<IRole>("Role", userRoleSchema);
export default UserRole;
User Schema
import mongoose, { Types } from "mongoose";
const { Schema } = mongoose;
export interface IUser extends mongoose.Document {
firstname:string;
lastname:string;
email:string;
password:string;
userRole:Types.ObjectId
}
const userSchema = new Schema({
firstname: String, // String is shorthand for {type: String}
lastname: String,
email: String,
password: String,
userRole: { type: Schema.Types.ObjectId, ref: "Role", required:true },
createdDate: { type: Date, default: Date.now },
});
// compile our model
const User = mongoose.model<IUser>("User", userSchema);
export default User;
Register Schemas
import mongoose from "mongoose";
import UserRole from "./role.schema";
import User from "./user.schema";
export const registerSchemas = () => {
mongoose.model('Role', UserRole.schema);
mongoose.model('User', User.schema);
}
I had to register all schemas like this after MongoDB connection initialization.
connectDB()
.then(() => {
console.log("Connected to MongoDb");
registerSchemas()
})
.catch((err) => console.log(err));
Then didn't get the "MissingSchemaError" message.

This is the error. (when I didn't register the UserRole model.)
User.findOne({ email: authData.email }, {}, { populate: ["userRole"] })
.then((user) => {
console.log("User", user);
if (user) {
if (user.password !== authData.password) {
res.send("invalid Email or Password");
} else {
res.send(user);
}
} else {
res.send("User not found!");
}
})
.catch((err) => {
console.log(err);
res.send(err);
});
Populate option didn't work without registerSchemas function.

While this answer may not be directly relevant to your question, I hope you find it helpful :)