我开发一个小应用程序与spring data mongo和angularjs。 这里是模型:春数据MongoDB的应用程序设计和数据聚合
public class Lease {
@Id
private String id;
private long created;
private Lessor lessor;
private Lessee lessee;
}
public class Payment {
@Id
private String id;
private Integer month;
private Integer year;
private Long amount;
private String leaseId;
}
我并没有插入支付模型,我需要它有一个ID,并在其自己的形式编辑。 在应用程序的主页上,它代表按月付款的租赁列表。在列表中选择一年。
如何更好地利用余额逐月加载租赁:可能是首次加载租赁,然后将ID注入付款或有更好的解决方案?目前我选择使用聚合:
LookupOperation lookupOperation = LookupOperation.newLookup().
from("payment").
localField("leaseId").
foreignField("id").
as("payments");
AggregationOperation match = Aggregation.match(Criteria.where("payments.year").is(year));
Aggregation aggregation = Aggregation.newAggregation(lookupOperation, match);
return mongoOperations.aggregate(aggregation, "lease", LeaseAggregation.class).getMappedResults();
的问题是,比赛是唯一在这里和例如如果在2017年没有支付,租赁的列表是空的。我看到mongo中的“addFields”功能尚未在spring数据mongodb中实现。对我来说更好的json回报将是:
{"leases" : [{"id" : 123, "created" : 12324343434, "payments" : [123, 455, 343, 323, 344, null, null, 332, 323, 232, 333, 434}]}
付款将代表某个特定年份的12个月。
如何用spring数据mongodb获得这个?
任何帮助,将不胜感激!