-
Notifications
You must be signed in to change notification settings - Fork 3
3.4 Filtering
Example: Search where the user wants results that name equals elvis and age equals 80.
http://localhost:3000/?name=elvis&age=80Result:
filters: {
"name": "elvis",
"age": 80
}Example: Search where the usar wants results that name equals elvis and city address equals New York.
http://localhost:3000/?name=elvis&address.city=New%20YorkResult:
filters: {
"name": "elvis",
"address.city": "New York"
}Example: Search where the usar wants results that name equals elvis and john.
http://localhost:3000/?name=elvis&name=johnResult:
filters: {
$and: [
{ name: 'elvis' },
{ name: john }
]}
}Example: Search where the usar wants results that name equals elvis or john.
http://localhost:3000/?name=elvis,johnResult:
filters: {
$or: [
{ name: 'elvis' },
{ name: john }
]}
}Example: Search where the usar wants results that age is greater than 30.
http://localhost:3000/?age=gt:30Result:
filters: {
age: { $gt: 30 }
} Example: Search where the usar wants results that age is greater or equal than 30
http://localhost:3000/?age=gte:30Result:
filters: {
age: { $gte: 30 }
} Example: Search where the usar wants results that age is lower than 30
http://localhost:3000/?age=lt:30Result:
filters: {
age: { $lt: 30 }
} Example: Search where the usar wants results that age is lower or equal than 30
http://localhost:3000/?age=lte:30Result:
filters: {
age: { $lte: 30 }
} Example: Search where the user want results that the name starts with value ‘elvis’.
http://localhost:3000/?name=elvis* Result:
filters: {
name: {
'$regex': '^elvis'
'$options': 'i',
}
}Example: Search where the user want results that the name ends with the value ‘elvis’.
http://localhost:3000/?name=*elvis Result:
filters: {
name: {
'$regex': 'elvis&'
'$options': 'i',
}
}Example: Search where the user wants results for name that contains the value ‘elvis’ in any position.
http://localhost:3000/?name=*elvis* Result:
filters: {
name: {
'$regex': 'elvis'
'$options': 'i',
}
}The name of parameter used in date filtering depends of the date_fields configuration used when instantiating the middleware. In the examples below, the default settings will be used, and the name of the date parameter will be created_at.
*Example: Search where the user wants results between 2018-12-10 and 2018-12-12.
http://localhost:3000/?start_at=2018-11-10&end_at=2018-12-10Result:
filters: {
$and: [
{ created_at: { $lt: '2018-12-10T23:59:59' }},
{ created_at: { $gte: '2018-11-10T00:00:00' }}]
}