The current implementation of the fsxa-api library does not support several standard MongoDB query operators, including $elemMatch and $exists.
This significantly limits the ability to express complex filter logic in CaaS queries. Specifically, it is currently impossible to apply $elemMatch.
Example Use Case:
I want to build a query that does the following:
- Check if a field (e.g.,
formData.tt_permissions.value) exists
- If it exists, apply
$elemMatch with $in on its contents
This is not possible currently because:
-
Using $elemMatch as an operator directly in the FSXA query builder results in:
-
Using $exists is also unsupported but one can use $eq with the null value instead, which works similarly.
-
I approached the problem using QueryBuilderQuery like this:
function getTypePermissionsFilter(type: PermissionType, typePermissions: Set<string> | Array<string>) {
const permissionFieldName = permissionHelper.mapPermissionTypeToFieldName(type);
return {
operator: LogicalQueryOperatorEnum.OR,
filters: [
{
operator: ComparisonQueryOperatorEnum.EQUALS,
field: `formData.tt_permissions.value.formData.${permissionFieldName}`,
value: null
},
{
operator: ComparisonQueryOperatorEnum.EQUALS,
field: `formData.tt_permissions.value.formData.${permissionFieldName}.value`,
value: []
},
{
operator: '$elemMatch',
field: `formData.tt_permissions.value.formData.${permissionFieldName}.value`,
value: {
'label': {
'$in': [...typePermissions]
}
}
}
]
} as LogicalFilter;
}
-
This problem can be solved with the filter CaaS query directly inside the URL. Here is the example for query by lt_role permission type:
{
"$or":[
{
"page.formData.tt_permissions.value.formData.lt_role":{
"$eq":null
}
},
{
"page.formData.tt_permissions.value.formData.lt_role.value":{
"$eq":[]
}
},
{
"page.formData.tt_permissions.value.formData.lt_role.value":{
"$elemMatch":{
"label":{
"$in":[
"VDs",
"Direct Sales"
]
}
}
}
}
]
}
Why This Matters:
These operators are part of the standard MongoDB query language and are crucial for:
- Safely querying optional fields
- Filtering documents by matching values in nested arrays or objects
- Preventing runtime errors due to accessing undefined properties
Requested Enhancement:
- Add support for
$elemMatch operator in the FSXA-API query builder.
- Optionally: expose a way to pass raw MongoDB filters to allow more advanced use cases without being constrained by the internal operator mapping logic.
The current implementation of the
fsxa-apilibrary does not support several standard MongoDB query operators, including$elemMatchand$exists.This significantly limits the ability to express complex filter logic in CaaS queries. Specifically, it is currently impossible to apply
$elemMatch.Example Use Case:
I want to build a query that does the following:
formData.tt_permissions.value) exists$elemMatchwith$inon its contentsThis is not possible currently because:
Using
$elemMatchas an operator directly in the FSXA query builder results in:Using
$existsis also unsupported but one can use$eqwith thenullvalue instead, which works similarly.I approached the problem using
QueryBuilderQuerylike this:This problem can be solved with the filter CaaS query directly inside the URL. Here is the example for query by
lt_rolepermission type:Why This Matters:
These operators are part of the standard MongoDB query language and are crucial for:
Requested Enhancement:
$elemMatchoperator in the FSXA-API query builder.