我在mongo中存储了这种树:
{
"00010":
{
"1.1":[1,3,4],
"4.0":[2,5]
},
"01000":
{
"1.4":[2,4],
"3.5":[3,5]
}
}
如果存在,我会在特定列表中推送新元素。
例如,如果新值是:
"00010":
{
"1.1":[6]
}
我想实现这一目标:
{
"00010":
{
"1.1":[1,3,4,6],
"4.0":[2,5]
},
"01000":
{
"1.4":[2,4],
"3.5":[3,5]
}
}
同时,如果新值是:
"00001":
{
"1.5":[2]
}
我想实现这一目标:
{
"00010":
{
"1.1":[1,3,4,6],
"4.0":[2,5]
},
"01000":
{
"1.4":[2,4],
"3.5":[3,5]
},
"00001":
{
"1.5":[2]
}
}
以此类推。
我正在尝试使用标准的MongoUpdateBolt(),但问题是查询和更新操作。我已经修改了execute()方法:
public void execute(Tuple tuple) {
try{
String idTuple = (String) tuple.getValue(0);
String attrs = (String) tuple.getValue(1);
String value = (String) tuple.getValue(2);
Document document = new Document();
List<String> tupleList = new ArrayList<String>();
tupleList.add(idTuple);
document.append("$push", tupleList);
//get query filter
Bson filter = queryCreator.createFilter(tuple);
Bson filter1 = Filters.and(Filters.eq("_id", attrs),
Filters.exists(value));
mongoClient.update(filter1, document, upsert);
this.collector.ack(tuple);
} catch (Exception e) {
this.collector.reportError(e);
this.collector.fail(tuple);
}
}
,但是此解决方案不起作用。有人可以帮我吗?