2014-09-24 4 views
2

임베디드 데이터의 배열 목록에 을 삽입하고 싶습니다. 나는 여러 가지 방법을 시도했지만 그것을 밖으로 만들 수 없었다. 내 데이터 구조는 이와 같습니다. 여기에 지정된 코드는mongodb에서 멀티 임베디드 데이터를 업데이트

Class X{ 
    Integer _id; 
    Arraylist<Y> objY; 
    } 

Class Y{ 
    Integer _id; 
    Arraylist<Z> objZ; 
    } 

Class Z{ 
     Integer _id; 
     String value; 
     String oldValue 
     } 

내가 클래스 X의 id 값을 알고 objZ 에 새 데이터를 삽입하려는 Y. 내가 봄 mongotemplate을 사용하고 내 원래의 데이터 구조에 단지 더미 참조입니다 . 스프링 몽고 템플릿 지원 여부? 누군가가이를 통해 나를 도울 수 있습니까?

미리 감사드립니다.

답변

3

나는 누군가를 도울 수 있기를 바랍니다.이 작업을 수행하려면 aggregetion을 사용하십시오.

Query searchUserQuery = new Query((Criteria.where("_id").is("542264c8e4b098972a1cf60c").and("leads._id").is("2")));// _id is the id of class X 
AggregationOperation match = Aggregation.match(searchUserQuery); 
AggregationOperation group = Aggregation.group("objY"); 
Aggregation aggregation = Aggregation.newAggregation(Aggregation.unwind("objY"),match, group); 

List<objY> asd=mongoOperation.aggregate(aggregation, "Name_of_ur_collection", B.class).getMappedResults(); 
ArrayList<Z> s=asd.get(0).getObjZ(); 
s.add("New Data to be added"); 
mongoOperation.updateFirst(searchUserQuery, Update.update("objY.$.objZ", s), X.class); 

이 클래스 Y.에

감사

를 배열 목록을 삽입합니다
관련 문제