我有一个数据库集合表,我想插入一个字段,如下所示,但我无法做到这一点

时间:2019-04-02 09:56:52

标签: java mongodb spring-boot

我的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

0 个答案:

没有答案