Khanetor
Khanetor

Reputation: 12304

Mongoose Schema "new" keyword

When declaring a mongoose schema, I noticed that using

mongoose.Schema({});

and

new mongoose.Schema({});

work.

Is there any difference? Which way is better?

Upvotes: 0

Views: 483

Answers (1)

levi
levi

Reputation: 25121

Its the same thing. From the source:

if (!(this instanceof Schema))
    return new Schema(obj, options);

If you omit new, it will just create an instance for you.

Upvotes: 6

Related Questions