0

使用 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"

插入数据库时​​如何删除“地图”?

4

1 回答 1

0

使用pojo类,就不会出现这样的问题

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

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

或尝试插入

Map<String, Object>
于 2014-12-24T15:55:21.420 回答