Difference between RegExp and raw // syntax for $regexFind captures

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Works as Designed
    • Priority: Major - P3
    • None
    • Affects Version/s: 4.4.4
    • Component/s: Querying
    • None
    • Query Optimization
    • ALL
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      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.

            Assignee:
            [DO NOT USE] Backlog - Query Optimization
            Reporter:
            Daniel Pasette (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: