MongoDB query $in with regex array of element

前端 未结 5 1461
野趣味
野趣味 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:57

    Here is simple way to transform /.*/ style regex.

    var sea = [ "/xd/", "/sd/", "/ad/" ];
    
    var rx = [];
    sea.forEach(function name(value) {
        var v = value.replace(/\//ig,"");
        rx.push(new RegExp(v));
    });
    
    db.paper.find({"category": {$in: rx}});
    

提交回复
热议问题