inglor
inglor

Reputation: 337

Saving enum into mongoDB

Is there a way to save enum into the mongoDB? I want to save something like:

public enum SnapshotType {
  EVENT,
  MEMORY
}

Upvotes: 13

Views: 12692

Answers (2)

Eve Freeman
Eve Freeman

Reputation: 33175

I assume you mean saving an enum value into a collection.

Basically, you just add it into your entity model, like so:

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

It will store it as a string in mongo, and automagically convert when you read it out.

Upvotes: 18

dicarsio
dicarsio

Reputation: 472

Just save the result. There are no schemas in mongo.

Upvotes: 1

Related Questions