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

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

    let test = `what your regex should 
    search`;
    
    collection.find({
        fieldName: {$regex: test}
    }).then(result => red.send(result));
    

    // tested on mongoose but should work on mongodb too

提交回复
热议问题