Hi All
I have a large aggregation pipeline which runs perfectly fine when tested in VSCode Playground, however when I transfer this into a App Services Function, which would normally be executed using a scheduled trigger I am getting errors with the use of $regex
The error I am receiving is:
Failed to optimize pipeline :: caused by :: $regexMatch needs 'regex' to be of type string or regex
The pipeline stage is as follows
const regExAdPriceExtractStage = {
$set: {
regexAdPrice: {
$cond: {
if: {
$regexMatch: {
input: '$price_text',
regex: /pw|week|pcm|month|psm|mth|p\.c\.m|pm|p\/m|p\.m|sqm|m2/,
options: 'i',
},
},
then: '$$REMOVE',
else: {
$regexFind: {
input: '$price_text',
regex: /(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d{1,2})?(?!\.?\d)/,
options: 'i',
},
},
},
},
},
};
It looks at a price_text
field and will either remove the field if some patters match, or it will extract a monetary amount from the field.
Reading the docs https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexMatch/ it says that I can use the pattern /<pattern>/
but for some reason this does not run when in an App Services Function.
Thanks heaps.