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

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

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Aggregation Framework
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible

      Description

      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" ] }

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: