const word = ctx.params.word
userModel.find({"name":{$regex: eval(`/${word}/ig`)}})
如果mongodb或者node版本低了,上面寫法很可能不管用,可以采用下面兩種寫法
title:eval("/"+title+"/ig") // 等同於 title:{$regex:title,$Option:"$ig"}
const word = ctx.params.word
userModel.find({"name":{$regex: eval(`/${word}/ig`)}})
如果mongodb或者node版本低了,上面寫法很可能不管用,可以采用下面兩種寫法
title:eval("/"+title+"/ig") // 等同於 title:{$regex:title,$Option:"$ig"}
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。