13

有没有办法将枚举保存到 mongoDB 中?我想保存类似的东西:

public enum SnapshotType {
  EVENT,
  MEMORY
}
4

2 回答 2

18

我假设您的意思是将枚举值保存到集合中。

基本上,您只需将其添加到您的实体模型中,如下所示:

@Document(collection = "MyEntity ")
public class MyEntity {
   public SnapshotType snapshotType;
}

它会将其作为字符串存储在 mongo 中,并在您读出时自动转换。

于 2012-03-06T22:30:06.550 回答
1

只需保存结果。mongo 中没有模式。

于 2012-03-06T18:34:11.377 回答