|
The captures are different when using RegExp vs // syntax.
Here's the output of a terminal session:
> db.foo.insert({job:"Engineering [122050] (open)"})
|
> db.foo.aggregate({$addFields: { returnObject: { $regexFind: { input: "$job", regex: RegExp('\[(.*)\]') }}}})
|
[ { _id: ObjectId("6060b22151a815916d99ba2f"),
|
job: 'Engineering [122050] (open)',
|
returnObject: { match: '(', idx: 21, captures: [] } } ]>
|
> db.foo.aggregate({$addFields: { returnObject: { $regexFind: { input: "$job", regex: /\[(.*)\]/} }}})
|
[ { _id: ObjectId("6060b22151a815916d99ba2f"),
|
job: 'Engineering [122050] (open)',
|
returnObject: { match: '[122050]', idx: 12, captures: [ '122050' ] } } ]
|
I am pretty sure that the syntax should be equivalent, but note the difference in the captures between the two queries. This is on an Atlas free tier (v4.4.4) cluster.
|