当使用嵌入式mongo文档我试图展开数组,但我收到异常像org.springframework.data.mapping.model.MappingInstantiationException:无法实例化java.util .List使用带参数的构造函数NO_CONSTRUCTOR。我就是写的查询,Mongo数据库java unwind操作聚合查询抛出异常
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
}
]
}
你能写代码在哪里调用聚合方法吗? –
@Andriy Simonov:我从另一个类中调用聚合函数,只有一种方法,我将使用动态用户配置文件Id调用该方法。但是,在这里我硬编码的用户配置文件ID为800. – Karthik