objectID is used for?

def add_comment(movie_id, user, comment, date):
comment_doc = {
“name”: user.name,
“email”: user.email,
“movie_id”: ObjectId(movie_id),
“text”: comment,
“date”: date
return db.comments.insert_one(comment_doc)

def update_comment(comment_id, user_email, text, date):
response = db.comments.update_one(
# we used the comment_id and user_email to verify that the user has
# permission to edit this comment
{"_id": ObjectId(comment_id), “email”: user_email},
{"$set": {“text”: text, “date”: date}}
return response
Why we use ObjectId with movie_id.why can’t we directly use movie_id.

We use ObjectId to cast the string movie_id to ObjectId data type. You can check by printing the movie_id in the console or in the test case. :slight_smile:
If we would be passing ObjectId type, then we wouldn’t be using this.


1 Like