mongoose 多条件模糊查询

it2026-02-07  0

node express mongoose 多条件模糊查询 // 模糊查询 router.get('/searchSome',(req, res, next)=>{ let regexp=new RegExp(req.query.keyword,'i') console.log(req.query.keyword); Product.find({$or:[ {title:{$regex:regexp}}, {description:{$regex:regexp}}, {details:{$regex:regexp}} ]},(err,doc)=>{ if(err){ res.send({ isSuccess: false, msg:"查询失败" }) } if(doc){ res.send({ isSuccess: true, data:doc }) } }) })
最新回复(0)