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
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
3
Q
How do you handle the request to limit fields in Mongoose?
A
- const x = req.query.fields.split(‘,’).join(‘ ‘); query = query.select(x);