Chapter 2 - Ticket: Get Comments -Solved

Hi,
I’m stocked in this Ticket.
Looking the results with postman and in the Compass, the results are OK, but in the
http://localhost:5000/status, returns is allways “The return from the api was incorrect”

I try all this 3 codes and the results are the same.

    pipeline = [ 
        { "$match": 
            { "_id": ObjectId(id) } }, 
            { "$lookup": 
                { "from": "comments", 
                  "let": {"id": "$_id"}, 
                  "pipeline": [ 
                     
                    {"$match": { "$expr": { "$eq": ["$movie_id", "$$id"] }}} 
                  ], "as": "movie_comments" } },
                  {"$sort": {"movie_comments.date": -1}} 
                ]

pipeline = [
{
“$match”: {
“_id”: ObjectId(id)
}
}, {
lookup": { "from": "comments", "let": {"id": "_id”},
“pipeline”: [
{"$match":{"$expr": {"$eq": ["$movie_id", “$$id”]}}},
{"$sort": {“date”: -1}}
],
“as”: “movie_comments”
}
}
]


    pipeline = [
        {
            "$match": {
                "_id": ObjectId(id)
            }
        }, {
            "$lookup": {
               "from": "comments", 
                "let": {"id": "$_id"}, 
            "pipeline": [
              {"$match":{"$expr": {"$eq": ["$movie_id", "$$id"]}}},
              {"$sort": {"date": -1}}
            ],   
               "as": "movie_comments"
            }
        }
    ]

    movie = db.movies.aggregate(pipeline).next()
    movie["comments"] = sorted(
        movie.get("comments", []),
        key=lambda c: c.get("date"),
        reverse=True
    )

Can any one please help me…
Thanks in advanced.
:vulcan_salute:

This working well at me

    pipeline = [
        {
            "$match": {
                "_id": ObjectId(id)
            }
        },
        {
           "$lookup": {
               "from": "comments",
               "let": { "id": "$_id" },
               "pipeline": [ { "$match": { "$expr": { "$eq": [ "$movie_id", "$$id" ] } } }, { "$sort": { "date": -1 } } ],
               "as": "comments"
           }
        }
    ]
1 Like

Thanks Gianfranco!

My problem was the “alias” comments.

Thanks! the force be with you…