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删除。