Spring Mongo嵌套内部查询

时间:2019-08-30 07:43:05

标签: java mongodb spring-boot java-8 spring-data-mongodb

尝试更新内部数组文档。嵌套数组分为三个级别。我可以删除到第二级,但不能更新第三级

       {  
   "id":"Test",
   "name":"Test",
    "sections":[  
   {  
      "sectionname":"Example1",
      "sectionroles":["test1", "test2", "test3"],
      "subcategory":[  
         {  
            "Value":"demo",
            "ValueId":"123333333333",
           "sectionroles":["test1", "test2", "test3"],
         },
         {  
            "Value":"Example2",
            "Value":"6577544333333",
            "sectionroles":["test1", "test2", "test3"],

         }
      ]
       }

我可以通过部分名称删除这些部分,但是不能删除该子类别。

     Query query = new Query(Criteria.where("name").is("Test"));
      query.fields().elemMatch("sections", 
       Criteria.where("sectionname").is("Example1"));
      Update update = new Update();
       update.pull("sections", new BasicDBObject("sectionname", 
       "Example1"));
       mongotemplate.updateMulti(query, update, "menu"); 

如何在现有条件中添加什么以删除或添加子类别中的任何值?

0 个答案:

没有答案