In my project I'm using SpringBoot 1.3.2 and org.springframework.data.mongodb.core.query.*
I'm trying to remove element from nested object array, in my main object i have array looking like this:
"sections" : [
{
"sectionId" : "56cc3c908f5e6c56e677bd2e",
"name" : "Wellcome"
},
{
"sectionId" : "56cc3cd28f5e6c56e677bd2f",
"name" : "Hello my friends"
}
]
Using Spring I want to delete record with sectionId 56cc3c908f5e6c56e677bd2e
This is way I'm trying do this:
Query query = Query.query(Criteria
.where("sections")
.elemMatch(
Criteria.where("sectionId").is("56cc3c908f5e6c56e677bd2e")
)
);
Update update = new Update().unset("sections.sectionId");
mongoTemplate.updateMulti(query, update, Offer.class);
Query is finding propper element but there is something wrong with Update and I don't know what so removing is not working.
Could any body can help me with this?