使用MongoTemplate插入JSONObject,如何防止" map"对象被添加到我的文档?

时间:2014-10-03 16:58:18

标签: spring mongodb insert mapping mongotemplate

使用MongoTemplate插入JSONObject我的代码是:

mongoTemplate.insert(jsonObject, collection);

我的JSONObject.toString()看起来像:

{"Event":{"Object":"Value","Object":"Value"}}

当它映射到MongoDB时,它看起来像:

{
"_id" : ObjectId("542ed489881654a415ca836d"),
"_class" : "org.json.JSONObject",
"map" : {
    "Event" : {
        "map" : {
            "Object":"Value", 
            "Object":"Value"

如何删除" map"从插入到我的数据库时添加?

1 个答案:

答案 0 :(得分:0)

使用pojo类,你就不会遇到这样的问题

public class User {
    private String password;
    // getter and setter;
}

User user = new User();
mongoTemplate.insert(user);

或尝试插入

Map<String, Object>