Sorting Flashcards

(5 cards)

1
Q

How do you use a URL to send a sorting query?

A

URL?sort=attr,atrr,atrr

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

What do the attributes after the first attribute mean in a sort request?

A

They are the attributes used to sort in case of a tie breaker from sorting using the previous attributes

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

In what order is sorting done by default?

A

Ascending order

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

How would you send a sorting request in descending order to MongoDB?

A

by adding a negative sign before the attribute you wish to sort with e.g. URL?sort=-attr

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

Write the code for handling sorting in Mongoose.

A

if(req.query.sort){const x = req.query.sort.split(‘,’).join(‘ ‘);query = query.sort(x)}else{query = query.sort(‘default attr’);}

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