Support for $regex operator in $filter of aggregation pipeline.

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Duplicate
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • None
    • Fully Compatible
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      Motivation: There should be support in aggregation pipeline for filtering an array using regex on a text field.

      Syntax Proposal :

      { $regex: [ "text", "pattern", "options" ] }
      

      Examples:
      Sample Document :

      { _id: 1, array: [ "DBMS", "mongodb", "MongoDB", "MONGODB", "SQL", "NOSQL" ] }
      

      Pipeline :

      db.collection.aggregate([ { $project: { filteredArray: { $filter: { input: "$array", as: "item", cond: { $regex: [ "$$item", "mongodb", "i" ] } } } } } ] )
      

      Output :

      { _id: 1, filteredArray: [ "mongodb", "MongoDB", "MONGODB" ] }

            Assignee:
            Asya Kamsky
            Reporter:
            Abhinandan Kothari
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: