Filtering Flashcards
(6 cards)
1
Q
How do you use the url to send queries?
A
url?attr=val&atrr=val
2
Q
How do you create a hardcopy for the req.query string obj?
A
let obj = {…req.query} ;
3
Q
How would you filter certain properties form the hardcopied obj?
A
const props = [‘fields’, ‘limit’, ‘page’, ‘sort’]; props.forEach((prop) => {delete obj[prop]});
4
Q
How would you send a query for handling greater than and less than queries?
A
URL?atrr[gt/lt/lte/gte]=val
5
Q
How would you filter the query String object so less/greater than queries are handled
A
- obj = JSON.stringify(obj).replace(/\b(gt|gte|lt|lte)\b/g, (key) => {return $${key}}); 2. obj = JSON.parse(obj);
6
Q
How would you do a database query for your final filtered object?
A
query = ModelName.find(obj);