Helper functions to convert filter and sort options to MongoDb syntax
Methods
# static convertFilter(filter) → {object}
Convert a filter config into a Mongo query expression
Parameters:
Name | Type | Description |
---|---|---|
filter |
array
|
The filter config to convert to Mongo syntax |
The Mongo query expression
object
Example
// If the filter config is:
{
type: "filter",
fieldId: "firstName",
operator: "contains",
value: "wilson"
}
// It will return:
{firstName: /wilson/}
# static convertFilterGroup(filterGroup) → {object}
Convert a filter config into a Mongo query expression
Parameters:
Name | Type | Description |
---|---|---|
filterGroup |
array
|
The filter config to convert to Mongo syntax |
The Mongo query expression
object
Example
// If the filter config is:
{
type: "group",
operator: "and",
filters: [
{
type: "filter",
fieldId: "firstName",
operator: "contains",
value: "wilson"
},
{
type: "filter",
fieldId: "birthDate",
operator: ">",
value: "2020-01-01"
}
]
}
// It will return:
{$and: [
{firstName: /wilson/},
{birthDate: {$gt: "2000-01-01"}}
]}
# static convertSort(sortArray) → {object}
Convert an array of sort options to Mongo style
Parameters:
Name | Type | Description |
---|---|---|
sortArray |
Array.<object>
|
The array to format to Mongo style |
- A single object with sort options
object
Example
// input:
[{birthDate: "asc"}, {lastName: "desc"}]
// output:
{birthDate: 1, lastName: -1}