Ticket:GetComments

@SuppressWarnings({ “rawtypes”, “unchecked” })
public Document getMovie(String movieId) {
if (!validIdValue(movieId)) {
return null;
}

List<Bson> pipeline = new LinkedList<>();
// match stage to find movie
Bson match = Aggregates.match(Filters.eq("_id", new ObjectId(movieId)));
pipeline.add(match);
// TODO> Ticket: Get Comments - implement the lookup stage that allows the comments to
// retrieved with Movies.

// Bson join = Aggregates.lookup(“comments”, “_id”, “movie_id”, “comments”);
// pipeline.add(join);
// pipeline.add(Aggregates.sort(Sorts.descending(“comments.date”)));
pipeline.addAll(Arrays.asList(Aggregates.lookup(“comments”, “_id”, “movie_id”, “comments”)
, Aggregates.sort(Sorts.descending(“date”))));
Document movie = moviesCollection.aggregate(pipeline).first();
return movie;

i am getting the proper size movie document. but not in sorted way. please someone help me.

Hi @Arul_46389,

Please look at the following post:

Kanika