Lookup query doesn't work!

I’m experiencing issue with one of Ticket. It’s for “Getting movie comments”.

I created the following query for “movies” collection:

List pipeline = new ArrayList<>();
// match stage to find movie
Bson match = Aggregates.match(Filters.eq("_id", new ObjectId(movieId)));
List<Variable> variablesToJoin = singletonList(new Variable(“id”, “$_id”));
List lookupPipeline = new ArrayList<>();
lookupPipeline.add(Aggregates.match(Filters.expr(Filters.eq("$movie_id", “$$id”))));
lookupPipeline.add(Sorts.descending("$date"));
Bson lookupComments = Aggregates.lookup(“comments”, variablesToJoin, lookupPipeline, “comments”);
pipeline.add(match);
pipeline.add(lookupComments);
// TODO> Ticket: Get Comments - implement the lookup stage that allows the comments to
// retrieved with Movies.
Document movie = moviesCollection.aggregate(pipeline).first();

I don’t understand where I’m wrong :frowning: Help me please

Here is error message:
com.mongodb.MongoCommandException: Command failed with error 40324 (Location40324): ‘Unrecognized pipeline stage name: ‘$date’’ on server mflix-shard-00-01-cml5x.mongodb.net:27017. The full response is { “operationTime” : { “$timestamp” : { “t” : 1582395592, “i” : 1 } }, “ok” : 0.0, “errmsg” : “Unrecognized pipeline stage name: ‘$date’”, “code” : 40324, “codeName” : “Location40324”, “$clusterTime” : { “clusterTime” : { “$timestamp” : { “t” : 1582395592, “i” : 1 } }, “signature” : { “hash” : { “$binary” : “ZX+ddv7oIVpr+DMwEZoTPAfnGb4=”, “$type” : “00” }, “keyId” : { “$numberLong” : “6794820429014892547” } } } }

First of all, my Java is very rusty to the point that it’s almost now non-existent, but it seems that everything looks good except this part:

  1. $date should be a string without “$”
  2. It’s missing Aggregates.sort()

By the way, it would have been easier to differentiate your code from the existing code if you’d started your code here

PS: It’s not recommended to publicly post potential solutions to labs

1 Like

Never mind. Already solved)

Aren’t you going to share how you did it? :slight_smile:

1 Like