MongoDB findBy..In 与 FindBy..Containing

我有一些班级活动:


@Data

@Document(collection = "event")

public class Event {

private String id;

private List<Type> types;

}

现在我想获取类型中包含某些 Type 实例的所有事件。我可以在 MongoRepository 类中编写两个方法:


List<Event> findByTypesContaining(List<Type> type, Pageable pageable);

或者


List<Event> findByTypesIn(List<Type> type, Pageable pageable);

两者都是作品。当我必须使用 ...Containing 和 ...In 时,它们之间有什么区别?


一只名叫tom的猫
浏览 116回答 1
1回答

眼眸繁星

findBy...Containing可以用于集合或字符串(以查看给定字符串是否是子字符串),而findBy...In只能用于集合。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java