Find by regex using Node.js and mongoose

Search by regex:

const ArticleModel = require('.article')
exports.getByAttr = (req, res, next) => {
  let search = {}
  if (req.query.search) {
    reg = new RegExp('.*' + req.query.search + '.*', 'ig')
    search = { attr: { $regex: reg } }
  }
  ArticleModel.find(search).then(result=>{
    return res.status(200).json({ result: result})
  })
}

Find by regex is equivalent and correspond to like method in sql:

select * from table where attr like("%search%")