Mongodb是一个无架构的文档数据库,但在spring数据中,有必要定义实体类和存储库类,如下所示:
实体类:
@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;
}
存储库类:
public interface UserRepository extends MongoRepository<User, String> {
    User findByUsername(String username);
}
无论如何在spring数据mongodb中使用map not class,以便服务器可以接受任何动态JSON数据,然后将其存储在BSON中而不需要任何预先定义的类?
我有一个可以包含动态键名的文档:
{
"_id" : ObjectId("51a29f6413dc992c24e0283e"),
"envinfo" : {
    "appName" : "MyJavaApp",
    "environment" : {
        "cpuCount" : 12,
        "heapMaxBytes" : 5724766208,
        "osVersion" : "6.2",
        "arch" : "amd64",
        "javaVendor" : "Sun Microsystems Inc.",
        "pid" : 44996,
        "javaVersion" : "1.6.0_38",
        "heapInitialBytes" : 402507520,
}
envinfo事先不知道这里的键。在Spring Data Mongodb中创建映射此文档的实体类的最佳方法是什么?