乐趣区

mongoose无字段模糊查询

 参数
const val = req.body.val;
const reg = new RegExp(val, 'i');
Model.find({
    $or: [{ key1: {$regex: reg} },
        {key2: {$regex: reg} },
        {key3: {$regex: reg} }
    ]
}).sort({timestamp: -1}).exec((err, docs) => {// do something})
退出移动版