相关疑难解决方法(0)

如何在$ match中的mongodb聚合查询中使用$ regex

我试图使用$regex内部$match,它不返回匹配的文件.

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);
  }
});
Run Code Online (Sandbox Code Playgroud)

谁能告诉我哪里出错或语法正确?


我甚至试过更换了

'Field2': { $regex: /Value_2/g }
Run Code Online (Sandbox Code Playgroud)

mongodb node.js

14
推荐指数
2
解决办法
3万
查看次数

标签 统计

mongodb ×1

node.js ×1