我有文件结构
"compilerOptions": {
"paths": {
"@angular/*": ["../../node_modules/@angular/*"],
"rxjs/*": ["../../node_modules/rxjs/*"]
},
}
我想基于{
"Name" : "MongoDB",
"Client" : "Database",
"Details" : [
{
"Date" : "2018-07-18",
"Code" : {
"new" : "5",
"new 1" : "3",
"new 2" : "4"
}
},
{
"Date" : "2018-07-19",
"Code" : {
"new" : "7",
"new 2" : "4"
}
}
]
}
将字段"new":"5"
更新为"Devops":"2
。
答案 0 :(得分:0)
我用Java尝试过,但是这段代码将新文档附加到同一日期
Bson过滤器= new Document(“ Name”,name);
Document h=new Document();
Document dd=new Document();
for(int i=0;i<ccode.length;i++)
{
h.append(ccode[i], hour[i]);
}
dd.append("Date", d);
dd.append("Code", h);
Document doc=new Document().append("Details",dd);
System.out.println(dd);
Bson updateOperationDocument = new Document("$push", doc);
collection.updateOne(filter, updateOperationDocument);