正则表达式Spring数据mongodb存储库 [英] Regular expression Spring data mongodb repositories
问题描述
早上好
我正在尝试使用查询注释将正则表达式与Spring数据mongodb存储库结合起来. 我想要的是在我的mongo文档的一个字符串属性中搜索一个子字符串. 我一直在谷歌和这里寻找,但没有找到任何优雅的东西,我想知道Spring资料库中是否有关于此的官方资料.
I´m trying to combine regular expression with Spring data mongodb repository using Query annotation. What I want is search one substring inside one string attribute of my mongo document. I have been looking in google and here, but I did not find anything elegant, and I was wondering if Spring data has something official about this using the repositories.
致谢.
推荐答案
这似乎是一个老问题,所以也许您已经有了一个解决方案,但是在这里我如何处理同样的问题:
It seems like an old question, so maybe you've already had a solution but here how I handled the same issue :
@Query(value = "{'title': {$regex : ?0, $options: 'i'}}")
Foo findByTitleRegex(String regexString);
使用/?0/
表示法将不起作用,因为Spring Data将带引号的String值放置
using the /?0/
notation won't work since Spring Data places a String value with quotes
这篇关于正则表达式Spring数据mongodb存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!