Get Comment ticket

I don’t get what I’m missing here…

List pipeline = new ArrayList<>();
Bson match = Aggregates.match(Filters.eq("_id", new ObjectId(movieId)));
pipeline.add(match);
List let = Arrays.asList(new Variable(“id”, “$_id”));
Bson joinedMatch = Aggregates.match(Filters.expr(Filters.eq(“movie_id”, “$$id”)));
Bson joinedSort = Aggregates.sort(Sorts.ascending(“name”));
List joinedPipeline = Arrays.asList(joinedMatch, joinedSort);
Bson lookup = Aggregates.lookup(“comments”, let, joinedPipeline, “comments”);
pipeline.add(lookup);
Document movie = moviesCollection.aggregate(pipeline).first();

I get this error: GetCommentsTest.testGetMovieComments:71 Comments list size does not match expected expected:<147> but was:<50329>

Hi @Shakira,

You are close. :slight_smile: There are few things you can re-write here:

  • In the ticket, its mentioned “The comments should be returned in order from most recent to least recent using the date key.” But I see different parameter in your sort function.
  • For expr, you can use Document.parse function with MongoDB filter query inside.

Kanika