I’m writing out a mongoose schema and realizing there’s a gap in my knowledge regarding what exactly is imported when you require a library. Here’s the code
const UserSchema = new mongoose.Schema({
username : {
type: String,
}
});
My questions
-
Is there any way to tell from the above code whether mongoose.Schema is a class or a constructor? I assume it’s a class but my constructor knowledge is hazy.
-
Normally I would expect to set ‘type’ to ‘String’ (with quotes) but here there are none in the above code. Does that mean that there is a variable called “String” in Schema?
-
Assuming #2 is yes, can we also infer that the class has some kind of logic to act on any argument that has an object key that has a string type and the string type is set to the ‘String’ variable? (Sorry for the long sentence but I’m trying to follow the reasoning precisely)