-1
I am trying to create a search with mongodb using "like" according to this site this site https://bognarjunior.wordpress.com/2015/05/18/consultas-avancadas-com-mongodb/
var results = await Hist.find({'cliente':/Jean/i}).sort({'pago':1, 'hora_saida':0})
console.log(results)
It works, however I would like to make it work using a variable that comes from my front-end, I tried that way and it didn’t work:
async search(req,res){
var search = "'cliente':"+'/'+req.body.search+'/i'
var results = await Hist.find({search}).sort({'pago':1, 'hora_saida':0})
console.log(results)
},
Remembering that the variable arrives correctly in the back end, but I can not use in the function that queries in the database.