MongoDB Aggregation of Parent document field in Spring -
i unable aggregate field parent document, example: class animal { int legs; int eyes; hashmap<string, object> subspecies; } class tiger extends animal{ int id; string name; string category; } public static void main(string args[]) { unwindoperation unwind = unwind("$subspecies"); aggregation agg = aggregation.newaggregation( aggregation.match(criteria.where("category").is("tigers")), unwind, aggregation.group("subspecies.bengaltiger").count().as("count"), project("count","subspecies.bengaltiger").and("subspecies.bengaltiger").previousoperation(), aggregation.sort(sort.direction.desc, "count") ); myservices services = new myservices(); //convert aggregation result list list<tigergroupcount> result = services.getaggregationlist(agg, tiger.class, tigergroupcount.class); system.out.println("result:" + result + ",,,,,,,,,," + result.size()); (tigergroupcount tigergroupcount: result) { system.out.println("status : " + tigergroupcount.groupname); system.out.println("count : " + tigergroupcount.count); } mlogger.info(""+result.size()); } class tigergroupcount { int id; string groupname; long count; } but here, able aggregate tiger.name field direct field in tiger.class. need access field - subspecies in parent class(animal.class). small appreciable. thank in advance.
Comments
Post a Comment