Regular expression to match all search terms

后端 未结 3 450
逝去的感伤
逝去的感伤 2021-01-25 00:47

I need a regular expression that will match on all terms in a set of search terms. If the user types \"bat sun\" then I need to match any text entries that have words starting w

3条回答
  •  渐次进展
    2021-01-25 01:20

    I think you can do something along the lines of:

    .find( { Item: { $regex : /\b[Term1]/i, $regex : /\b[Term2]/i, $regex : /\b[TermN]/i } } );

    See: http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-RegularExpressions

提交回复
热议问题