2016-07-23 3 views
1

임베디드 mongo 문서로 작업 할 때 배열을 풀려고하지만 org.springframework.data.mapping.model.MappingInstantiationException 같은 예외가 발생합니다. java.util을 인스턴스화하지 못했습니다. 인수와 함께 생성자 NO_CONSTRUCTOR를 사용하여 .List. 당신의 집계 결과이집계 쿼리에서 Mongo db java unwind 작업

AggregationResults<Logs> results = mongoOps.aggregate(agg, "logs", Logs.class); 

같은 로그 오브젝트의 목록 후받는 사람의 기수가 잘못 인 경우 I가 쓴 쿼리,

Aggregation agg = newAggregation(
     unwind("recipients"), 
match(Criteria.where("recipients.userId").is("800").andOperator(Criteria.where("recipients.status").is(false) 
       ))); 
    Logs.java 
private String id; 
private String userId; 
private String conversationId; 
private Date createdDate; 
private List<Recipients> recipients; 

Recipients.java 

private String userId; 
private boolean status; 

데이터

{ 
"_id" : ObjectId("579099e6000fda45000c0054"), 
"userId" : "800", 
"conversationId" : "57907e5f000fda45000c004b", 
"createdDate" : ISODate("2016-07-21T09:46:14.602Z"), 
"recipients" : [ 
     { 
       "userId" : "800", 
       "status" : false 
     }, 
     { 
       "userId" : "900", 
       "status" : false 
     } 
] 
    } 
{ 
"_id" : ObjectId("579099e9000fda45000c0055"), 
"userId" : "530a7998-ba3f-4366-8d21-bb1ca688cfdb", 
"conversationId" : "57907e5f000fda45000c004b", 
"createdDate" : ISODate("2016-07-21T09:46:17.915Z"), 
"recipients" : [ 
     { 
       "userId" : "800", 
       "status" : true 
     }, 
     { 
       "userId" : "900", 
       "status" : false 
     } 
] 
} 
{ 
"_id" : ObjectId("5790adda000fda2444d6ccdf"), 
"userId" : "530a7998-ba3f-4366-8d21-bb1ca688cfdb", 
"conversationId" : "578df6cf000fda2640b77c45", 
"createdDate" : ISODate("2016-07-21T11:11:22.522Z"), 
"recipients" : [ 
     { 
       "userId" : "800", 
       "status" : false 
     }, 
     { 
       "userId" : "530a7998-ba3f-4366-8d21-bb1ca688cfdb", 
       "status" : true 
     } 
] 
} 
{ 
"_id" : ObjectId("5790adde000fda2444d6cce0"), 
"userId" : "530a7998-ba3f-4366-8d21-bb1ca688cfdb", 
"conversationId" : "578df6cf000fda2640b77c45", 
"createdDate" : ISODate("2016-07-21T11:11:26.479Z"), 
"recipients" : [ 
     { 
       "userId" : "800", 
       "status" : false 
     }, 
     { 
       "userId" : "530a7998-ba3f-4366-8d21-bb1ca688cfdb", 
       "status" : true 
     } 
] 
} 
+0

집계 메소드를 호출하는 코드를 작성할 수 있습니까? –

+0

@Andriy Simonov : 다른 클래스에서 호출 중입니다. 집계 함수가 한 메서드에 있는데, 동적 사용자 프로필 ID를 사용하여 해당 메서드를 호출합니다. 그러나 여기에 사용자 프로필 ID를 800으로 하드 코드했습니다. – Karthik

답변

1

설정 . unwind 후에는 수신자 필드가 단일 문서를 보유하기 때문에 List와 대조되는 수신자 여야합니다.

Logs.java 
    private String id; 
    private String userId; 
    private String conversationId; 
    private Date createdDate; 
    private Recipients recipients; <-- 
+0

하지만이 방법을 사용하면받는 사람을 한 명만 저장할 수 있습니까? 단일 레코드에 대해받는 사람 배열을 저장해야합니다. – Karthik

+1

그러면 두 개의 클래스가 필요합니다. 저장 및 읽기와 같은 일반 작업에 대한 로그와 집계 결과에 대한 추가 클래스입니다. LogsAggregationResult와 같이 호출 할 수 있습니다. –

+0

내 레코드를 저장 한 테이블과 다른 집계 결과에 대해 다른 테이블을 쿼리하는 방법은 무엇입니까? 그것이 효과가 있다고 생각합니까? – Karthik

관련 문제