mongodb中的待特殊字符的模糊查询需要转义下才能查到

(name: /wo*2hjf/  查不到

   name: /wo\*2hjf/  查得到  )                   

let str=wo*2hjf;

let filter1={

name: new RegExp(str)

};

let filter2={

name: new RegExp(str.replace(/\*/g,'\\*'))

};

db.find({filter1})//查不到

db.find({filter2})//能查到

相关文章:

  • 2022-12-23
  • 2021-08-07
  • 2022-12-23
  • 2021-08-07
  • 2021-05-26
  • 2021-08-31
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 1970-01-01
  • 2021-11-12
  • 2021-06-25
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案