How to use dynamic schema in spring data with mongodb?

Viewed 12613

Mongodb is a no-schema document database, but in spring data, it's necessary to define entity class and repository class, like following:

Entity class:

@Document(collection = "users")
public class User implements UserDetails {
    @Id private String userId;
    @NotNull @Indexed(unique = true) private String username;
    @NotNull private String password;
    @NotNull private String name;
    @NotNull private String email;
}

Repository class:

public interface UserRepository extends MongoRepository<User, String> {
    User findByUsername(String username);
}

Is there anyway to use map not class in spring data mongodb so that the server can accept any dynamic JSON data then store it in BSON without any pre-class define?

1 Answers
Related