What is the difference between the two in Schema creation in mongoose as I searched the docs and googled but can't get any significant result. I am a mongoose starter and wanted to know if thr is any significant difference between the two.
First -
var personSchema = new mongoose.Schema({....});
Second-
var personSchema = mongoose.Schema({....});
There is essentially no difference. Both forms return an instance of a "Schema" with the arguments provided. Some people prefer this type of syntax for clarity on creating a "new" object instance:
var Schema = require("mongoose").Schema;
var personSchema = new Schema({ });
It really is just a matter of preference to what makes a cleaner coding convention to you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.