I am trying to use $regex in $match without returning the relevant documents.
db.collection('MyCollection', function (err, collection) { collection.aggregate([ { $match: { 'Code': 'Value_01', 'Field2': { $regex: '/Value_2/g' } } }, { $project: { _id: 1, CodeNumber: '$Code', FieldName2: '$Field2' } } ], function (err, Result_doc) { console.log(Result_doc); } });
Can someone tell me where this is going wrong or the correct syntax?
I even tried with a replacement
'Field2': { $regex: /Value_2/g }
source share