Hello, I’m trying to grasp mongoose .populate()
method. When we are declaring a field in Schema we are pointing to type of the field using key/value pairs like:
const personSchema = Schema({
name: String,
However when we are declaring the field that only have an ID reference to the other model like this:
const personSchema = Schema({
stories: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Story' }],
});
we need to use this long mongoose.Schema.Types.ObjectId
. Why we can’t just use something like ObjectId
since when we are declaring the string for example we only write String
- not mongoose.Schema.Types.String
?