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

后端 未结 5 1541
清酒与你
清酒与你 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:35

    You need to create a regular expression object from the string using the RegExp constructor as the /.../ syntax is only for use with literals.

    var stream = collection.find({"FirstName": new RegExp(val)}).stream();
    

提交回复
热议问题