-
Type: New Feature
-
Resolution: Duplicate
-
Priority: 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" ] }- duplicates
-
SERVER-11947 Add a regex expression to the aggregation language
- Closed