使用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"从插入到我的数据库时添加?
答案 0 :(得分:0)
使用pojo类,你就不会遇到这样的问题
public class User {
private String password;
// getter and setter;
}
User user = new User();
mongoTemplate.insert(user);
或尝试插入
Map<String, Object>