MongoDB query $in with regex array of element

前端 未结 5 1462
野趣味
野趣味 2020-12-16 18:09

Ok i am trying to implement a query, which is trying to perform regex search ( which contains an array list ) on a bunch of document

Its hard for me to explain...so

5条回答
  •  渐次进展
    2020-12-16 18:56

    For this you can add a regular expression to each item in the array, you can do it in the following way.

    data = ['hoLA','Que','TAL', 'Nueva'];
    data  = data.map(function(v, i){return new RegExp(v, 'i')});
    MyCollection.find({"thing": {$in : data}}, function(err, data){
        if (err) {
            console.log(err)
        }else{
            data.forEach(function(item){
                console.log(item.nombre);
            })
        }
    });
    

提交回复
热议问题