Filtering Flashcards

(6 cards)

1
Q

How do you use the url to send queries?

A

url?attr=val&atrr=val

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

How do you create a hardcopy for the req.query string obj?

A

let obj = {…req.query} ;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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]});

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

How would you send a query for handling greater than and less than queries?

A

URL?atrr[gt/lt/lte/gte]=val

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

How would you filter the query String object so less/greater than queries are handled

A
  1. obj = JSON.stringify(obj).replace(/\b(gt|gte|lt|lte)\b/g, (key) => {return $${key}}); 2. obj = JSON.parse(obj);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How would you do a database query for your final filtered object?

A

query = ModelName.find(obj);

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