'is mongoose.model() a "CONSTRUCTOR"?
Most of the examples of creating model are like this:
const model = mongoose.model("Collection", schema);
But, if I write:
const model = new mongoose.model("Collection", schema);
That just works fine. I wonder what are the difference between them? Also, which one is the best practice. Moreover, If mongoose.model() is a constructor, how can we use it's instance as a constructor? Like so:
const model = new mongoose.model("Collection", schema); // if 'mongoose.model' a constructor,
const doc = new model({data: data}); // how can we use it's instance as a constructor?
doc.save();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
