Ticket: Create / Update Comments UI issue

try:

    """
    Ticket: Get Comments

    Please implement a $lookup stage in this pipeline to find all the
    comments for the given movie. The movie_id in the `comments` collection
    can be used to refer to the _id from the `movies` collection.

    Embed the joined comments in a new field called "comments".
    """

    # TODO: Get Comments
    # Implement the required pipeline.
    pipeline=[
    {
    '$match': {
        '_id':ObjectId(id)}
    
    }, {
    '$lookup': {
        'from': 'comments', 
        'let': {'d': '$_id'}, 
        'pipeline': [
            { '$match': {'$expr': {'$eq': ['$movie_id', '$$d']}}},{'$sort':{'date':1}} ], 
        'as': 'comments'
     }
     }
      ]
   

    movie = db.movies.aggregate(pipeline).next()
    return movie

any suggested adjustment

I am not sure they want to sort ascending. I would try that first.

they, else you wont pass the get comments test

From the lab instructions:

The comments should be returned in order from most recent to least recent using the date key.

Anyway, I sort with -1 and it works. May be test test is wrong if they insert test comments in the natural order that correspond to the date it is possible the test does not catch such an error.

yes -1 works for get comments, i mistakenly edited before posting it here. but still failing create and update comments

Are the errors different or the same as before?

same with diferent value to assert

Please post the errors.

co2

found the answer. i to ObjectId to my id field

3 Likes

Hi Chika,

Finally what was the issue?

May I use ObjectId(movieId) and/pr ObjectId(CommentId) ?

Thanks in advance,

Xavi

Same issue here the code seems to be correct with other users but test case fails.

How you fixed it, can you share the code please.

Fixed it: when implementing ticket Get Comments I missed the sort feature {"$sort": {“date”: -1}.
this ticket passed however the subsequent ticket update relies on this sort mechanism and failed.

I have the same problem, can you help me if you have got the answer.

unable to pass the update test code n UI , test is getting passed . Getting error unable to update . Have tried fixing the test script but still not getting the code .

It is not advised to update test scripts. What is the error when you are running unit tests? Considering you have not updated those files.

Kanika