mongodb 使用IN运算符的查询忽略不区分大小写的特殊字符

1l5u6lss  于 2023-06-22  发布在  Go
关注(0)|答案(1)|浏览(167)

需要在java中为mongo集合写一个查询。
在集合中查找字符串列表(IN查询),忽略不区分大小写的特殊字符。

String result = String.join("|", item.getList());
searchQuery.put("columnName", Pattern.compile(result, Pattern.CASE_INSENSITIVE));

字符串包含特殊字符时出现模式错误

uttx8gqw

uttx8gqw1#

您可以使用Pattern.quote()将项目视为文字:

String result = item.getList()
        .stream()
        .map(Pattern::quote)
        .collect(Collectors.joining("|"));

相关问题