I added below code in getMovie():
List pipeline = new ArrayList<>();
// match stage to find movie
Bson match = Aggregates.match(eq("_id", new ObjectId(movieId)));
// TODO> Ticket: Get Comments - implement the lookup stage that allows the comments to
// retrieved with Movies.
Bson lookUp = Aggregates.lookup(“comments”,"_id",“movie_id”,“comments”);
Bson unwind = Aggregates.unwind("$comments");
Bson sort = Aggregates.sort(Sorts.descending(“comments.date”));
List movies = new ArrayList();
List ‘movies’ in last line has 2 documents sorted on date basis for email id ‘573a1390f29313caabcd418c’. So this seems to be in line what we need.
So I just need to group the documents.
So I add following after sort:
Bson groupCommentsSet = Aggregates.group("$comments.movie_id", Accumulators.addToSet(“comments”, “$comments”));
But this doesn’t work. Comments are in ascending order of dates. Moreover, other fields are also lost.