Virtual Properties Flashcards

1
Q

What is a virtual property?

A

It is a property that is returned with documents during a query but is not stored in the database

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you create a virtual property in Mongoose?

A

SchemaName.virtual(‘virtual property name’).get(function (){return this.attr * this.attr} ) ;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you make Mongoose aware of virtual properties?

A

const SchemaName = new mongoose.Schema({}, { toJSON: {virtuals: true}, toObject: {virtuals: true} })

How well did you know this?
1
Not at all
2
3
4
5
Perfectly