Trialcoder
Trialcoder

Reputation: 6004

Use of new keyword in mongoose schema design

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({....});

Upvotes: 0

Views: 157

Answers (1)

Neil Lunn
Neil Lunn

Reputation: 151122

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.

Upvotes: 2

Related Questions