假设,每个轨道都有类别的子集。
@Document
public class Track {
String name;
HashSet<Category> categories;
...
}
@Document
public class Category {
String name;
...
}
最好使用什么集合?
这取决于您的标准。
ArrayList会快一点,并且在加载的Java对象中使用更少的内存。它将保持元素的顺序。
HashSet 将强制执行唯一性,更快地检查包含,无序。
这本质上与不使用MongoDB时使用哪一个的问题相同...