有没有一种方法可以将枚举类型保存到MongoDB中?我想要保存这样的内容:
public enum SnapshotType {
EVENT,
MEMORY
}
我假设你的意思是将枚举值保存到一个集合中。
基本上,你只需要把它添加到实体模型中,就像这样:
@Document(collection = "MyEntity ")
public class MyEntity {
public SnapshotType snapshotType;
}
它将把数据以字符串的形式存储到mongo中,在读取时会自动进行转换。
只需保存结果。MongoDB 中没有模式。