Mongoose Middleware Flashcards

1
Q

What are the types of important Mongoose middleware you should know?

A

Document, Query and Aggregation Middleware

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

Mongoose middleware can either be?

A

pre or post hooks

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

What is the format for writing Mongoose middleware?

A

schemaName.pre/post(‘event’, function (next(pre) or val, next(post)){next()});

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

When does the save event occur?

A

During the create() and save() Mongoose methods

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

What are some events in the query middleware?

A

find/findById, or any Mongoose query function name

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

During a pre-hook, what does the this keyword refer to for the document, query and aggregation middleware?

A

document middleware => the object about to be stored, query middleware => the query currently being processed, aggregation middleware => the aggregation object

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

During a post hook, what keyword is available for each middleware?

A

document middleware => the the document that has been saved to the database, query middleware => the this keyword referring to the query is still available

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

How do you run a query middleware for all events starting with a particular word?

A

/^word/ as the event

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

How do you add an element at the top/front of an array?

A

array.unshift(data)

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

How do you get access to the aggregation pipeline (array of object operations) in the aggregation object?

A

this._pipeline

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

Create all three types of middleware for any use case and compare them with what you did in the course.

A

Do on PC

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