Get Comments lab sort

Hello everyone, I was able to do make all test run correctly with the exception of sorting the comments array after performing $lookup, I’m not sure how am I supposed to it and I don’t recall it was covered?

here my code, this is returning a good results but the comments are not sorted

Bson lookup = new Document("$lookup",
        new Document("from", "comments")
                .append("localField", "_id")
                .append("foreignField", "movie_id")
                .append("as", "comments"));
List<Bson> pipeline = new ArrayList<>();
// match stage to find movie
Bson match = Aggregates.match(eq("_id", new ObjectId(movieId)));
// retrieved with Movies.
Document movie = moviesCollection.aggregate(pipeline).first();

Hi @Home_79665,

As explained in the lecture, we use expressive lookup. We need to use pipeline stages for sorting the comments.


ok, thanks, I’m able to do the expressive lookup in compass, but I guess I need to construct the BSON manually for java? when I export to java code I get an error “Unrecognized option to $lookup: let”

This post will be helpful. You need to use Aggregates model for Java.