AssertionError in User Management ticket

I am getting the following error on running the user management ticket for add_user method and db.users.createIndex({“email” : 1},{unique: true}) does not seem to help

Hi @Arushi_29302,

You do not need to create any index on the collection unless the lab explicitly asks to add. For the issue, try checking if user exists before creating a user.

Kanika

I have tried the insert_one() and update_one() with upsert value true as well. Then upon visit the forum discussion related to the error I am getting I got to know about the create index method. Please let me know how to proceed.

Warm Regards,
Arushi

Hello Again,

Shall use the following code snippet in add_user() method:

info={
“name”: name,
“email”: email,
“password”: hashedpw
}
if db.users.find_one({“email”:email}) is None:
db.users.insert_one(info)

This should work. Otherwise you can use try catch block as well.

Kanika

Hello Kanika,

It is still throwing the same error.
I even tried the following:

info={“name”: name,“email”: email,“password”: hashedpw}
if get_user(email) is None:
db.users.insert_one(info)

where get_user(email) is a method implemented in db.py to find document in users collection by email and it is used in other methods as shown as such.

Sent you a message :slight_smile:

Kanika

I am also getting problem in User-Management. Can anybody give me the actual codes which i will execute. From last 4hour i am in this trouble…
Shadab…

That would completely defeat the purpose of taking a course to learn.

Share the problem you have and we will help. A screenshot is best as we see the whole context.