How can I use a regex variable in a query for MongoDB

后端 未结 5 1547
清酒与你
清酒与你 2020-11-30 06:10

I would like to make query MongoDB for documents based on a regex expression that I contruct. For e.g I have constructed a simple regex as follows that is a combination of a

5条回答
  •  醉话见心
    2020-11-30 06:44

    Use the following code to use dynamic value in regex with or operations

    {$match: { $or: [{ 'title': { $regex:  request.query.val, $options: 'i'} }, { 'skills_required': { $regex:  request.query.val, $options: 'i'} }] }},
    

提交回复
热议问题