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

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

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

      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@mongodb.com Asya Kamsky
            Reporter:
            kothariabhi02 Abhinandan Kothari
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: