MongoDB findBy..In 与 FindBy..Containing
MongoDB findBy..In vs FindBy..Containing
我有一些class事件:
@Data
@Document(collection = "event")
public class Event {
private String id;
private List<Type> types;
}
现在我想获取所有在类型中包含某些 Type 实例的事件。我可以在 MongoRepository class:
中写两个方法
List<Event> findByTypesContaining(List<Type> type, Pageable pageable);
或
List<Event> findByTypesIn(List<Type> type, Pageable pageable);
两者都是作品。当我必须使用 ...Containing 和 ...In 时,它们之间有什么区别?
查看 documentation,您可以看到,
findBy...Containing
可用于 collection 或字符串(查看给定字符串是否为子字符串)
而
findBy...In
只能用于 Collection。
我有一些class事件:
@Data
@Document(collection = "event")
public class Event {
private String id;
private List<Type> types;
}
现在我想获取所有在类型中包含某些 Type 实例的事件。我可以在 MongoRepository class:
中写两个方法List<Event> findByTypesContaining(List<Type> type, Pageable pageable);
或
List<Event> findByTypesIn(List<Type> type, Pageable pageable);
两者都是作品。当我必须使用 ...Containing 和 ...In 时,它们之间有什么区别?
查看 documentation,您可以看到,
findBy...Containing
可用于 collection 或字符串(查看给定字符串是否为子字符串)
而
findBy...In
只能用于 Collection。