Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

spring boot mongodb update subdocument

final Query query = new Query(new Criteria().andOperator(
        Criteria.where("_id").is("id"),
        Criteria.where("listA").elemMatch(Criteria.where("_id").is("id"))
));
final Update update = new Update().addToSet("listA.$.listB", stuff).set("listA.$.thing", "thing");
final WriteResult wr = mongoOperations.updateFirst(query, update, "collectionName");
 
PREVIOUS NEXT
Tagged: #spring #boot #mongodb #update #subdocument
ADD COMMENT
Topic
Name
2+2 =