mongodb - Spring JPA Query 查找属于查询字符串的所有字符串
问题描述
我想用一个例子来解释我的问题。在 mongodb 我有一个字符串列。现在我想列出该列中属于我的查询字符串的所有字符串。
例如,如果我的查询字符串是“这是我的测试字符串”。
我的理想结果是
“这个”、“这是”、“这是我的”、“是我的”、“是我的测试”、“这是我的测试”、“这是我的测试字符串”等..,
在 mysql 中,我知道 "%Like%" 会处理。我在 mongo JPA 中尝试了“Like”,但没有运气。
谁能帮我?
解决方案
As JB mentioned, there is no Mongo JPA, but I assume you want a similar behavior as what Spring Data JPA does for you which is what Spring Data MongoDB does.
To do so, you need to use In and a collection of the string part of your query. So you will need to break your string first.
In your repository, use Spring Data's query DSL with In i.e:
public interface YourDocumentRepository extends MongoRepository<YourDocument, ClassTypeOfYourId> {
public List<YourDocument> findByNameIn(string[] text);
}
If the name of your string field is superDuper
, the example would be:
public List<YourDocument> findBySuperDuperIn(string[] text);
You should adjust. For more detail, take a look at the reference or some example here.
推荐阅读
- c - 有时使用 localtime() 函数会出现错误的时间
- android - Flutter 为 Android 和 IOS 设计不同的设计
- python - 如果文件已关闭,为什么我会收到 PermissionError?(Python)
- sql - Power BI - 使用 Dax 根据 Group By 进行筛选
- json - 如何在 Superset 中格式化图表?
- function - Google 表格 - 将多个 IF 函数合并到一个单元格中
- sas - 在 SAS 中创建组合
- python - ValueError:形状不匹配:标签的形状(收到的 (1,))应该等于 logits 的形状,除了最后一个维度(收到的 (10, 30))
- reactjs - React pdf 查看器 - 使用来自本地服务器的工作人员
- python - SettingWithCopyWarning,如何阻止它?