Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-55583

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

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Works as Designed
    • 4.4.4
    • None
    • Querying
    • None
    • ALL

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

              backlog-query-optimization Backlog - Query Optimization
              dan@mongodb.com Daniel Pasette
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: