我的MongoDB表结构是
{
"_id": "5c9b5b1c9eca130d305b047b",
"projectID": "PRO004",
"_class":
"com.services.webserviceApi.webServiceInformation.TestCaseInformation",
"modules": [
{
"moduleName": "NewModule",
"testCases": [
{
"testCaseName": "TC005",
"testCaseID": "TC_PRO004_1"
},
{
"testCaseName": "TC006",
"testCaseDescription": "Search SIN Number",
"testCaseID": "TC_PRO004_2"}]}]}
现在我想添加一个新字段“ requestURl ”,其数据为 关于 TestCaseName 的“ www.google.com ”,其中 “ testCaseName ”是“ TC005 ”
我尝试了汇总
List<AggregationOperation> list = new ArrayList<AggregationOperation>();
list.add(Aggregation.match(Criteria.where("projectID").is("PRO004")));
list.add(Aggregation.unwind("modules"));
list.add(Aggregation.match(Criteria.where("modules.moduleName").is(moduleName)));
list.add(Aggregation.unwind("modules.testCases")); list.add(Aggregation.match(Criteria.where("modules.testCases.testCaseID").is("TC_PRO004_2")));
//list.addField(!no such method to add field)
TypedAggregation<TestCases> agg = Aggregation.newAggregation(TestCases.class,
list); String s = mongoTemplate.aggregate(agg, TestCases.class,
TestCases.class).getRawResults().toJson();
but still there is no method as $addfield here so i a unable to add it