我正在尝试在现有的 Mongo 文档中添加新字段。
{
"_id" : ObjectId("51e390ade4b0a29154453698"),
"group_name" : "om",
"target_audience" : {
"gender" : "male",
"section" : "Item 4",
"catagory" : "Eletronics",
"location" : {
"country" : "Item 3",
"state" : "Item 3",
"city" : "Item 4"
}
}
}
这是我的文档。我想在此文档中添加更多字段。我编写以下代码。但不是在同一文档中添加记录,而是替换之前的记录。我的Java代码是:
BasicDBObject doc=new BasicDBObject();
BasicDBObject q=new BasicDBObject("group_name",selectedgn);
doc.put("date_from",frm);
doc.put("date_too",too);
doc.put("description",desc);
doc.put("url",url);
BasicDBObject doc1=new BasicDBObject();
doc1.put("Notification",doc);
con.coll.update(q,doc1);