Unrecognized expression '$regex'

{
  from: 'contacts', 
  let: {  "mcontactId" : '$clientContact.contactId',
    'today' : "17/10"
  },
   pipeline: [
  { '$match': { 
      $expr: {
        $and: [
            { "$eq": [ "$uniqueId",  "$$mcontactId" ] },
            {
              $or:[{"birthDate": {"$regex": '$$today'}},
	             {"spouseBirthdate": {"$regex":'$$today'}},
		    {"weddingAnniversary": {"$regex":'$$today'}}
		]
            }
          ]
      }
    }
  }
    ,
     { '$project': {
       'userId':1,
          'uniqueId': 1,
          'firstName': 1,
          'lastName': 1
        }
     }
   ],
  as: 'contact'
}

Not able to get desired output. Getting “Unrecognized expression ‘$regex’” error

Hello @KingMen_Agent, Welcome to the MongoDB Developer Community forum!

You need to use Aggregation Expression Operators within the $expr operator - hence the error: “Unrecognized expression ‘$regex’” . The $regex is a MongoDB Query Language operator.

The following link has the Regular Expression operators you can use in your query.

1 Like