I am trying to run an aggregation, which at the end should enable a search over all fields.
My idea was to use { “$match”: { “$or”: [ { "$regexMatch: {}} ] } } and just add all field names with the same search string in my Javascript application. But I get an error “MongoServerError: unknown top level operator: $regexMatch”, not sure how to change the aggregation.
let agg = [{
"$match": {
"$or": [
{
"$regexMatch": {
"input": "$field1",
"regex": new RegExp(search),
"options": "i"
}
},
{
"$regexMatch": {
"input": "$field2",
"regex": new RegExp(search),
"options": "i"
}
},
... more fields ...
]
}
}]