Spring Mongo nested inner query

被刻印的时光 ゝ 提交于 2020-01-05 03:59:10

问题


Trying to update an inner array document. There are three levels of the nested array. I am able to remove till the second level but not able to update the third level

       {  
   "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"],

         }
      ]
       }

I am able to remove the sections through the section name but not able to remove the subcategory.

     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"); 

What do I add in the existing Criteria to remove or add any value in a subcategory ???

来源:https://stackoverflow.com/questions/57722566/spring-mongo-nested-inner-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!