Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法将枚举保存到 mongoDB 中?我想保存类似的东西:
public enum SnapshotType { EVENT, MEMORY }
我假设您的意思是将枚举值保存到集合中。
基本上,您只需将其添加到您的实体模型中,如下所示:
@Document(collection = "MyEntity ") public class MyEntity { public SnapshotType snapshotType; }
它会将其作为字符串存储在 mongo 中,并在您读出时自动转换。
只需保存结果。mongo 中没有模式。