Limiting Fields Flashcards

(3 cards)

1
Q

How do you send a request to limit the result fields from the URL?

A

URL?fields=attr,attr,attr

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

How would you ensure a certain attribute is not returned from a query?

A

query.select(‘-attr’). i.e. add a negative sign in front of the attribute when querying for data

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

How do you handle the request to limit fields in Mongoose?

A
  1. const x = req.query.fields.split(‘,’).join(‘ ‘); query = query.select(x);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly