M220P Create_Update_Comment

Ok… I understand that I need to access the user object… From what I have been taught that is using dot notation to get into the user object. so…
to get the name it should be user.name and email should be user.email, so to access this in the document construct it should be

document = {“name” : user.name, “email” : user.email, “movie_id”: movie_id, “comment” : comment, “date”: date}

This SHOULD create the document to insert in the insert command… But it appears that I am not accessing the user object.

Below is my code.

def add_comment(movie_id, user, comment, date):
    Inserts a comment into the comments collection, with the following fields:

    - "name"
    - "email"
    - "movie_id"
    - "text"
    - "date"

    Name and email must be retrieved from the "user" object.
    # TODO: Create/Update Comments
    # Construct the comment document to be inserted into MongoDB.
    comment_doc = {"name": user.name, "email": user.email, "movie_id": movie_id, "comment": comment, "date": date}
    return db.comments.insert_one(comment_doc)

It seems I am messing up on the user object… But I tried user.get_user() but there is no get user… So… The only other thing I know of is to use dot notation and drill down into the user object like this… user.name and user.email

Am I on the right track?

Hey @David_Thompson,

Your code shows that you are thinking in the right direction. :smile: Using dot to access name and email from user is done in the right way. However, for movie_id, it should be

 "movie_id": ObjectId(movie_id)

Also, there is no field name comment, it should be text as given in the instructions:

"text": comment

Feel free to reach out for anything else as well.


@Satyam ,
Thanks… I caught the “comment” : comment error and fixed it after I submitted this ticket… But I didn’t know I had to use the ObjectId(movie_id)… Thanks.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.