我想用一个例子来解释我的问题。在mongodb中我有一个String列。现在我想列出该列中属于我的查询字符串的所有字符串。
例如,如果我的查询字符串是“这是我的测试字符串”。
我的理想结果是
“这是”,“这是”,“这是我的”,“是我的”,“是我的考试”,“这是我的考试”,“这是我的考试字符串”等...,
在mysql中我知道“%Like%”会处理。我在mongo JPA中试过“赞”但没有运气。
谁能帮我?
正如JB所提到的,没有Mongo JPA,但我认为你想要一个类似于Spring Data JPA为你做的行为,就像Spring Data MongoDB那样。
为此,您需要使用In和查询的字符串部分的集合。所以你需要先破坏你的字符串。
在您的存储库中,使用Spring Data queryDSL with In:
public interface YourDocumentRepository extends MongoRepository<YourDocument, ClassTypeOfYourId> {
public List<YourDocument> findByNameIn(string[] text);
}
如果字符串字段的名称是superDuper
,则示例为:
public List<YourDocument> findBySuperDuperIn(string[] text);
你应该调整。有关更多详细信息,请查看the reference或一些示例here。